from copy import deepcopy
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod=10**9+7

dp=[[0]*m for i in range(n)]
ss=[0]*m
buf=[0]*m
count=0
for i in range(n):
    for j in range(m):
        if s[i]==t[j]:
            if i==0 or j==0:
                dp[i][j]=1
                count+=1
                count=count%mod
            else:
                dp[i][j]=ss[j-1]+1
                count+=dp[i][j]
                count=count%mod
        if j>0:
            buf[j]=ss[j]+dp[i][j]+buf[j-1]-ss[j-1]
        else:
            buf[j]=ss[j]+dp[i][j]
    ss=deepcopy(buf)
print(count+1)