import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N, M = MAP()
    S = LIST()
    T = LIST()
    dp = [[0 for i in range(N + 1)] for j in range(M + 1)]
    for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
    print((dp[M][N] + 1) % mod)

if __name__ == '__main__':
    main() import sys sys def input(): return sys.stdin.readline()[:-1] input def ceil(x, y=1): return int(-(-x // y)) ceil x x y=1 y 1 def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST list(map(int, input().split())) for _ in range(h) for _ in range(h) _ range(h) range h for _ in range(h) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def MAT(h): return [list(map(int, input().split())) for _ in range(h)] MAT h h def Yes(): print('Yes') Yes def No(): print('No') No def YES(): print('YES') YES def NO(): print('NO') NO sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 def main():
    N, M = MAP()
    S = LIST()
    T = LIST()
    dp = [[0 for i in range(N + 1)] for j in range(M + 1)]
    for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
    print((dp[M][N] + 1) % mod) main N, M = MAP() N MAP() MAP M S = LIST() S LIST() LIST T = LIST() T LIST() LIST [0 for i in range(N + 1)] for j in range(M + 1) for j in range(M + 1) j range(M + 1) range M + 1 M 1 for j in range(M + 1) [0 for i in range(N + 1)] dp = [[0 for i in range(N + 1)] for j in range(M + 1)] dp [[0 for i in range(N + 1)] for j in range(M + 1)] for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
     j range(M) range M for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
     i range(N) range N if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
     S[i] == T[j] S[i] S i T[j] T j dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 (dp[j][i+1] + dp[j+1][i] + 1) % mod dp[j][i+1] + dp[j+1][i] + 1 dp[j][i+1] + dp[j+1][i] dp[j][i+1] [j] dp j i+1 i 1 dp[j+1][i] [j+1] dp j+1 j 1 i 1 mod dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod dp[j][i+1] + dp[j+1][i] - dp[j][i] dp[j][i+1] + dp[j+1][i] dp[j][i+1] [j] dp j i+1 i 1 dp[j+1][i] [j+1] dp j+1 j 1 i dp[j][i] [j] dp j i mod print((dp[M][N] + 1) % mod) print (dp[M][N] + 1) % mod dp[M][N] + 1 dp[M][N] [M] dp M N 1 mod if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST def ceil(x, y=1): return int(-(-x // y)) def ceil(x, y=1): return int(-(-x // y)) ceil def No(): print('No') def No(): print('No') No def MAT(h): return [list(map(int, input().split())) for _ in range(h)] def MAT(h): return [list(map(int, input().split())) for _ in range(h)] MAT INF = float('inf') float('inf') INF def Yes(): print('Yes') def Yes(): print('Yes') Yes def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP def INT(): return int(input()) def INT(): return int(input()) INT mod = 10 ** 9 + 7 10 ** 9 + 7 mod def NO(): print('NO') def NO(): print('NO') NO def main():
    N, M = MAP()
    S = LIST()
    T = LIST()
    dp = [[0 for i in range(N + 1)] for j in range(M + 1)]
    for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
    print((dp[M][N] + 1) % mod) def main():
    N, M = MAP()
    S = LIST()
    T = LIST()
    dp = [[0 for i in range(N + 1)] for j in range(M + 1)]
    for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
    print((dp[M][N] + 1) % mod) main def YES(): print('YES') def YES(): print('YES') YES def input(): return sys.stdin.readline()[:-1] def input(): return sys.stdin.readline()[:-1] input
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MAT(h): return [list(map(int, input().split())) for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    N, M = MAP()
    S = LIST()
    T = LIST()
    dp = [[0 for i in range(N + 1)] for j in range(M + 1)]
    for j in range(M):
        for i in range(N):
            if S[i] == T[j]:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] + 1) % mod
            else:
                dp[j+1][i+1] = (dp[j][i+1] + dp[j+1][i] - dp[j][i]) % mod
    print((dp[M][N] + 1) % mod)

if __name__ == '__main__':
    main()
