n,m=map(int,input().split())
s=input().split()
t=input().split()
dp=[[1]*(m+1)]+[[1]+[0]*m for _ in range(n)]
for i in range(n):
	for j in range(m):
		dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7)
print(dp[-1][-1]) n,m=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m s=input().split() s input().split() ().split () input split t=input().split() t input().split() ().split () input split [1]+[0]*m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [1]+[0]*m [1] 1 [0]*m [0] 0 m dp=[[1]*(m+1)]+[[1]+[0]*m for _ in range(n)] dp [[1]*(m+1)]+[[1]+[0]*m for _ in range(n)] [[1]*(m+1)] [1]*(m+1) [1] 1 m+1 m 1 [[1]+[0]*m for _ in range(n)] for i in range(n):
	for j in range(m):
		dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7) i range(n) range n for j in range(m):
		dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7) j range(m) range m dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7) dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7) dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]) dp[i+1][j]+dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 dp[i][j]*(s[i]!=t[j]) dp[i][j] [i] dp i j s[i]!=t[j] s[i] s i t[j] t j 10**9+7 10**9 10 9 7 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 dp=[[1]*(m+1)]+[[1]+[0]*m for _ in range(n)] [[1]*(m+1)]+[[1]+[0]*m for _ in range(n)] dp m=map(int,input().split()) map(int,input().split()) m s=input().split() input().split() s t=input().split() input().split() t n,m=map(int,input().split()) map(int,input().split()) n
n,m=map(int,input().split())
s=input().split()
t=input().split()
dp=[[1]*(m+1)]+[[1]+[0]*m for _ in range(n)]
for i in range(n):
	for j in range(m):
		dp[i+1][j+1]=(dp[i+1][j]+dp[i][j+1]-dp[i][j]*(s[i]!=t[j]))%(10**9+7)
print(dp[-1][-1])