import sys

N,M=map(int, sys.stdin.readline().split())
S=[None]+map(int, sys.stdin.readline().split())
T=[None]+map(int, sys.stdin.readline().split())

dp=[ [ 0 for m in range(M+1) ] for n in range(N+1) ]

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

mod=10**9+7
for i in range(1,N+1):
	for j in range(1,M+1):
		if S[i]==T[j]:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]
		else:
			dp[i][j]+=dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]
		dp[i][j]%=mod
		

print dp[-1][-1]%mod
			