n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0]*m for _ in range(n)]
sum=[[0]*m for _ in range(n)]
mod=10**9+7
for i in range(n):
  if s[i]==t[0]:
    dp[i][0]=1
  else:
    dp[i][0]=0
for i in range(m):
  if t[i]==s[0]:
    dp[0][i]=1
  else:
    dp[0][i]=0
sum[0][0]=dp[0][0]
for i in range(1,n):
  sum[i][0]=sum[i-1][0]+dp[i][0]
for i in range(1,m):
  sum[0][i]=sum[0][i-1]+dp[0][i]
for i in range(1,n):
  for j in range(1,m):
    if s[i]==t[j]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:
      dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod
ans=0
for i in range(n):
  for j in range(m):
    ans+=dp[i][j]
    ans=ans%mod
print((ans+1)%mod) 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 [0]*m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0]*m [0] 0 m dp=[[0]*m for _ in range(n)] dp [[0]*m for _ in range(n)] [0]*m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0]*m [0] 0 m sum=[[0]*m for _ in range(n)] sum [[0]*m for _ in range(n)] mod=10**9+7 mod 10**9+7 10**9 10 9 7 for i in range(n):
  if s[i]==t[0]:
    dp[i][0]=1
  else:
    dp[i][0]=0 i range(n) range n if s[i]==t[0]:
    dp[i][0]=1
  else:
    dp[i][0]=0 s[i]==t[0] s[i] s i t[0] t 0 dp[i][0]=1 dp[i][0] [i] dp i 0 1 dp[i][0]=0 dp[i][0] [i] dp i 0 0 for i in range(m):
  if t[i]==s[0]:
    dp[0][i]=1
  else:
    dp[0][i]=0 i range(m) range m if t[i]==s[0]:
    dp[0][i]=1
  else:
    dp[0][i]=0 t[i]==s[0] t[i] t i s[0] s 0 dp[0][i]=1 dp[0][i] [0] dp 0 i 1 dp[0][i]=0 dp[0][i] [0] dp 0 i 0 sum[0][0]=dp[0][0] sum[0][0] [0] sum 0 0 dp[0][0] [0] dp 0 0 for i in range(1,n):
  sum[i][0]=sum[i-1][0]+dp[i][0] i range(1,n) range 1 n sum[i][0]=sum[i-1][0]+dp[i][0] sum[i][0] [i] sum i 0 sum[i-1][0]+dp[i][0] sum[i-1][0] [i-1] sum i-1 i 1 0 dp[i][0] [i] dp i 0 for i in range(1,m):
  sum[0][i]=sum[0][i-1]+dp[0][i] i range(1,m) range 1 m sum[0][i]=sum[0][i-1]+dp[0][i] sum[0][i] [0] sum 0 i sum[0][i-1]+dp[0][i] sum[0][i-1] [0] sum 0 i-1 i 1 dp[0][i] [0] dp 0 i for i in range(1,n):
  for j in range(1,m):
    if s[i]==t[j]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:
      dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod i range(1,n) range 1 n for j in range(1,m):
    if s[i]==t[j]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:
      dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod j range(1,m) range 1 m if s[i]==t[j]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:
      dp[i][j]=0
     s[i]==t[j] s[i] s i t[j] t j dp[i][j]=(sum[i-1][j-1]+1)%mod dp[i][j] [i] dp i j (sum[i-1][j-1]+1)%mod sum[i-1][j-1]+1 sum[i-1][j-1] [i-1] sum i-1 i 1 j-1 j 1 1 mod dp[i][j]=0 dp[i][j] [i] dp i j 0 sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod sum[i][j] [i] sum i j (sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j] sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1] sum[i-1][j]+sum[i][j-1] sum[i-1][j] [i-1] sum i-1 i 1 j sum[i][j-1] [i] sum i j-1 j 1 sum[i-1][j-1] [i-1] sum i-1 i 1 j-1 j 1 dp[i][j] [i] dp i j mod ans=0 ans 0 for i in range(n):
  for j in range(m):
    ans+=dp[i][j]
    ans=ans%mod i range(n) range n for j in range(m):
    ans+=dp[i][j]
    ans=ans%mod j range(m) range m ans+=dp[i][j] ans dp[i][j] [i] dp i j ans=ans%mod ans ans%mod ans mod print((ans+1)%mod) print (ans+1)%mod ans+1 ans 1 mod mod=10**9+7 10**9+7 mod n,m=map(int,input().split()) map(int,input().split()) n ans=0 0 ans s=list(map(int,input().split())) list(map(int,input().split())) s ans=ans%mod ans%mod ans sum=[[0]*m for _ in range(n)] [[0]*m for _ in range(n)] sum m=map(int,input().split()) map(int,input().split()) m t=list(map(int,input().split())) list(map(int,input().split())) t dp=[[0]*m for _ in range(n)] [[0]*m for _ in range(n)] dp ans+=dp[i][j] dp[i][j] ans
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
dp=[[0]*m for _ in range(n)]
sum=[[0]*m for _ in range(n)]
mod=10**9+7
for i in range(n):
  if s[i]==t[0]:
    dp[i][0]=1
  else:
    dp[i][0]=0
for i in range(m):
  if t[i]==s[0]:
    dp[0][i]=1
  else:
    dp[0][i]=0
sum[0][0]=dp[0][0]
for i in range(1,n):
  sum[i][0]=sum[i-1][0]+dp[i][0]
for i in range(1,m):
  sum[0][i]=sum[0][i-1]+dp[0][i]
for i in range(1,n):
  for j in range(1,m):
    if s[i]==t[j]:
      dp[i][j]=(sum[i-1][j-1]+1)%mod
    else:
      dp[i][j]=0
    sum[i][j]=(sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i][j])%mod
ans=0
for i in range(n):
  for j in range(m):
    ans+=dp[i][j]
    ans=ans%mod
print((ans+1)%mod)