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)#Tをiまで見た時のSとの部分列のも場合の数
for i in range(n):
    tmp = dp[:]
    for j in range(m):
        if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod
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):
    tmp = dp[:]
    for j in range(m):
        if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod i range(n) range n tmp = dp[:] tmp dp[:] dp : for j in range(m):
        if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod j range(m) range m if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod S[i]==T[j] S[i] S i T[j] T j dp[j+1] = (tmp[j+1] + dp[j])%mod dp[j+1] dp j+1 j 1 (tmp[j+1] + dp[j])%mod tmp[j+1] + dp[j] tmp[j+1] tmp j+1 j 1 dp[j] dp j mod dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod dp[j+1] dp j+1 j 1 (tmp[j+1]+dp[j]-tmp[j])%mod tmp[j+1]+dp[j]-tmp[j] tmp[j+1]+dp[j] tmp[j+1] tmp j+1 j 1 dp[j] dp j tmp[j] tmp j mod print(dp[-1]) print dp[-1] dp -1 m = map(int,input().split()) map(int,input().split()) m tmp = dp[:] dp[:] tmp n,m = map(int,input().split()) map(int,input().split()) n T = list(map(int,input().split())) list(map(int,input().split())) T dp = [1]*(m+1) [1]*(m+1) dp S = list(map(int,input().split())) list(map(int,input().split())) S mod = 10**9+7 10**9+7 mod
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)#Tをiまで見た時のSとの部分列のも場合の数
for i in range(n):
    tmp = dp[:]
    for j in range(m):
        if S[i]==T[j]:
            dp[j+1] = (tmp[j+1] + dp[j])%mod
        else:
            dp[j+1] =(tmp[j+1]+dp[j]-tmp[j])%mod
print(dp[-1])
