N,M=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod=10**9+7
c=[0]*N
d=[0]*M
dp=[[ 0 for i in range(M)] for j in range(N)]
sm=[[ 0 for i in range(M)] for j in range(N)]
for i in range(N):
  if t[0]==s[i]:
    dp[i][0]=1
    c[i]=1
for i in range(M):
  if s[0]==t[i]:
    dp[0][i]=1
    d[i]=1
s1=0
for i in range(N):
  s1=s1+c[i]
  sm[i][0]=s1
s1=0
for i in range(M):
  s1=s1+d[i]
  sm[0][i]=s1
for i in range(1,N):
  for j in range(1,M):
    if s[i] != t[j]:
      dp[i][j]=0
    else:
      dp[i][j]=sm[i-1][j-1]+1
    sm[i][j]=sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]+dp[i][j]
ans=(sm[N-1][M-1]+1)%mod
print(ans)