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