n,m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
PR = 1000000007

dp = [[0 for j in range(m+1)] for i in range(n+1)]

for i in range(n+1):
	dp[i][0] = 1

for j in range(m+1):
	dp[0][j] = 1 

for i in range(n):
	for j in range(m):
		#aa
		sumI = 0
		sumI = dp[i+1][j]
#		for jj in range(0,j):
#			if s[i] == t[jj]:
#				sumI=(sumI + dp[i][jj]) % PR
		
		sumJ = 0
		sumJ = dp[i][j+1]
#		for ii in range(0,i):
#			if t[j] == s[ii]:
#				sumJ=(sumJ + dp[ii][j]) % PR
		
		if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp)
print(dp[n][m]) n,m = map(int, input().split()) n 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 PR = 1000000007 PR 1000000007 [0 for j in range(m+1)] for i in range(n+1) for i in range(n+1) i range(n+1) range n+1 n 1 for i in range(n+1) [0 for j in range(m+1)] dp = [[0 for j in range(m+1)] for i in range(n+1)] dp [[0 for j in range(m+1)] for i in range(n+1)] for i in range(n+1):
	dp[i][0] = 1 i range(n+1) range n+1 n 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for j in range(m+1):
	dp[0][j] = 1  j range(m+1) range m+1 m 1 dp[0][j] = 1 dp[0][j] [0] dp 0 j 1 for i in range(n):
	for j in range(m):
		#aa
		sumI = 0
		sumI = dp[i+1][j]
#		for jj in range(0,j):
#			if s[i] == t[jj]:
#				sumI=(sumI + dp[i][jj]) % PR
		
		sumJ = 0
		sumJ = dp[i][j+1]
#		for ii in range(0,i):
#			if t[j] == s[ii]:
#				sumJ=(sumJ + dp[ii][j]) % PR
		
		if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp) i range(n) range n for j in range(m):
		#aa
		sumI = 0
		sumI = dp[i+1][j]
#		for jj in range(0,j):
#			if s[i] == t[jj]:
#				sumI=(sumI + dp[i][jj]) % PR
		
		sumJ = 0
		sumJ = dp[i][j+1]
#		for ii in range(0,i):
#			if t[j] == s[ii]:
#				sumJ=(sumJ + dp[ii][j]) % PR
		
		if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp) j range(m) range m sumI = 0 sumI 0 sumI = dp[i+1][j] sumI dp[i+1][j] [i+1] dp i+1 i 1 j sumJ = 0 sumJ 0 sumJ = dp[i][j+1] sumJ dp[i][j+1] [i] dp i j+1 j 1 if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp) s[i] == t[j] s[i] s i t[j] t j dp[i+1][j+1] = (sumI + sumJ) % PR dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (sumI + sumJ) % PR sumI + sumJ sumI sumJ PR dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (sumI + sumJ - dp[i][j]) % PR sumI + sumJ - dp[i][j] sumI + sumJ sumI sumJ dp[i][j] [i] dp i j PR print(dp[n][m]) print dp[n][m] [n] dp n m n,m = map(int, input().split()) map(int, input().split()) n dp = [[0 for j in range(m+1)] for i in range(n+1)] [[0 for j in range(m+1)] for i in range(n+1)] dp sumI = 0 0 sumI s = list(map(int, input().split())) list(map(int, input().split())) s PR = 1000000007 1000000007 PR sumJ = 0 0 sumJ t = list(map(int, input().split())) list(map(int, input().split())) t sumI = dp[i+1][j] dp[i+1][j] sumI m = map(int, input().split()) map(int, input().split()) m sumJ = dp[i][j+1] dp[i][j+1] sumJ
n,m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
PR = 1000000007

dp = [[0 for j in range(m+1)] for i in range(n+1)]

for i in range(n+1):
	dp[i][0] = 1

for j in range(m+1):
	dp[0][j] = 1 

for i in range(n):
	for j in range(m):
		#aa
		sumI = 0
		sumI = dp[i+1][j]
#		for jj in range(0,j):
#			if s[i] == t[jj]:
#				sumI=(sumI + dp[i][jj]) % PR
		
		sumJ = 0
		sumJ = dp[i][j+1]
#		for ii in range(0,i):
#			if t[j] == s[ii]:
#				sumJ=(sumJ + dp[ii][j]) % PR
		
		if s[i] == t[j]:
			dp[i+1][j+1] = (sumI + sumJ) % PR
		else:
			dp[i+1][j+1] = (sumI + sumJ - dp[i][j]) % PR
#		print("i: %d j: %d  sumI: %d sumJ:%d dp[i][j]:%d" % (i+1,j+1,sumI,sumJ,dp[i+1][j+1]))

#print(dp)
print(dp[n][m])
