import sys
input = sys.stdin.readline
mod=10**9+7
n,m=map(int,input().split())
S=[int(i) for i in input().split()]
T=[int(i) for i in input().split()]
DP=[[0]*(m+1) for _ in range(n+1)]
SUM=[[0]*(m+1) for _ in range(n+1)]
for i in range(1,n+1):
  for j in range(1,m+1):
    if S[i-1]==T[j-1]:
      DP[i][j]=1
      for k in range(i):
        for l in range(j):
          DP[i][j]+=DP[k][l]
          DP[i][j]%=mod
ans=1
for i in range(1,n+1):
  for j in range(1,m+1):
    ans=(ans+DP[i][j])%mod
print(ans)
        