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 
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[j]=1
            else:
                dp[j]=ss[j-1]+1
            count+=dp[j]
            count=count%mod
        else:
            dp[j]=0
        buf[j]=ss[j]+dp[j]
        if j>0:
            buf[j]+=buf[j-1]-ss[j-1]
    #ss=buf
    for i in range(m):
        ss[i]=buf[i]
print(count+1)