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 
buf=[[0]*m for i in range(2)]
count=0
t=1
for i in range(n):
    t=1-t
    for j in range(m):
        if j==0:
            flag=0
        else:
            flag=1
        if s[i]==T[j]:
            dp[j]=1
            dp[j]+=flag*buf[t][j-1]
            count+=dp[j]
        else:
            dp[j]=0
        buf[1-t][j]=buf[t][j]+dp[j]
        buf[1-t][j]+=flag*(buf[1-t][j-1]-buf[t][j-1])
print((count+1)%mod)