N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
d = [[0 for i in range(M + 1)] for j in range(N + 1)]
mod = 1000000007

for i in range(1, N+1):
	sum = 0
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			sum += d[i - 1][j - 1] + 1
		d[i][j] = (d[i - 1][j] + sum) % mod
print((d[N][M] + 1)%mod) N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [0 for i in range(M + 1)] for j in range(N + 1) for j in range(N + 1) j range(N + 1) range N + 1 N 1 for j in range(N + 1) [0 for i in range(M + 1)] d = [[0 for i in range(M + 1)] for j in range(N + 1)] d [[0 for i in range(M + 1)] for j in range(N + 1)] mod = 1000000007 mod 1000000007 for i in range(1, N+1):
	sum = 0
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			sum += d[i - 1][j - 1] + 1
		d[i][j] = (d[i - 1][j] + sum) % mod i range(1, N+1) range 1 N+1 N 1 sum = 0 sum 0 for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			sum += d[i - 1][j - 1] + 1
		d[i][j] = (d[i - 1][j] + sum) % mod j range(1, M + 1) range 1 M + 1 M 1 if S[i - 1] == T[j - 1]:
			sum += d[i - 1][j - 1] + 1
		 S[i - 1] == T[j - 1] S[i - 1] S i - 1 i 1 T[j - 1] T j - 1 j 1 sum += d[i - 1][j - 1] + 1 sum d[i - 1][j - 1] + 1 d[i - 1][j - 1] [i - 1] d i - 1 i 1 j - 1 j 1 1 d[i][j] = (d[i - 1][j] + sum) % mod d[i][j] [i] d i j (d[i - 1][j] + sum) % mod d[i - 1][j] + sum d[i - 1][j] [i - 1] d i - 1 i 1 j sum mod print((d[N][M] + 1)%mod) print (d[N][M] + 1)%mod d[N][M] + 1 d[N][M] [N] d N M 1 mod N, M = list(map(int, input().split())) list(map(int, input().split())) N d = [[0 for i in range(M + 1)] for j in range(N + 1)] [[0 for i in range(M + 1)] for j in range(N + 1)] d sum = 0 0 sum M = list(map(int, input().split())) list(map(int, input().split())) M sum += d[i - 1][j - 1] + 1 d[i - 1][j - 1] + 1 sum S = list(map(int, input().split())) list(map(int, input().split())) S T = list(map(int, input().split())) list(map(int, input().split())) T mod = 1000000007 1000000007 mod
N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = list(map(int, input().split()))
d = [[0 for i in range(M + 1)] for j in range(N + 1)]
mod = 1000000007

for i in range(1, N+1):
	sum = 0
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			sum += d[i - 1][j - 1] + 1
		d[i][j] = (d[i - 1][j] + sum) % mod
print((d[N][M] + 1)%mod)