def getlist():
	return list(map(int, input().split()))

N, M = getlist()
S = getlist()
T = getlist()

L = [[1 for i in range(N + 1)] for j in range(M + 1)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007

print(L[M][N] % 1000000007) def getlist():
	return list(map(int, input().split())) getlist return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split N, M = getlist() N getlist() getlist M S = getlist() S getlist() getlist T = getlist() T getlist() getlist [1 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) [1 for i in range(N + 1)] L = [[1 for i in range(N + 1)] for j in range(M + 1)] L [[1 for i in range(N + 1)] for j in range(M + 1)] for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007 i range(1, N + 1) range 1 N + 1 N 1 for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007 j range(1, M + 1) range 1 M + 1 M 1 if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007 S[i - 1] == T[j - 1] S[i - 1] S i - 1 i 1 T[j - 1] T j - 1 j 1 L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007 L[j][i] [j] L j i (L[j - 1][i] + L[j][i - 1]) % 1000000007 L[j - 1][i] + L[j][i - 1] L[j - 1][i] [j - 1] L j - 1 j 1 i L[j][i - 1] [j] L j i - 1 i 1 1000000007 L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007 L[j][i] [j] L j i (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007 L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1] L[j - 1][i] + L[j][i - 1] L[j - 1][i] [j - 1] L j - 1 j 1 i L[j][i - 1] [j] L j i - 1 i 1 L[j - 1][i - 1] [j - 1] L j - 1 j 1 i - 1 i 1 1000000007 print(L[M][N] % 1000000007) print L[M][N] % 1000000007 L[M][N] [M] L M N 1000000007 S = getlist() getlist() S M = getlist() getlist() M N, M = getlist() getlist() N def getlist():
	return list(map(int, input().split())) def getlist():
	return list(map(int, input().split())) getlist L = [[1 for i in range(N + 1)] for j in range(M + 1)] [[1 for i in range(N + 1)] for j in range(M + 1)] L T = getlist() getlist() T
def getlist():
	return list(map(int, input().split()))

N, M = getlist()
S = getlist()
T = getlist()

L = [[1 for i in range(N + 1)] for j in range(M + 1)]
for i in range(1, N + 1):
	for j in range(1, M + 1):
		if S[i - 1] == T[j - 1]:
			L[j][i] = (L[j - 1][i] + L[j][i - 1]) % 1000000007
		else:
			L[j][i] = (L[j - 1][i] + L[j][i - 1] - L[j - 1][i - 1]) % 1000000007

print(L[M][N] % 1000000007)