mod=10**9+7
N,M=map(int,input().split())
S=[int(i) for i in input().split()]
T=[int(i) for i in input().split()]
dp=[[0 for j in range(M)] for i in range(N)]
ans=[[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N+1):
    ans[i][0]=1
for j in range(M+1):
    ans[0][j]=1
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j]=ans[i][j]
        else:
            dp[i][j]=0
        ans[i+1][j+1]=dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j]
        ans[i+1][j+1]%=mod
print(ans[N][M]) mod=10**9+7 mod 10**9+7 10**9 10 9 7 N,M=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split M int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i S=[int(i) for i in input().split()] S [int(i) for i in input().split()] int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i T=[int(i) for i in input().split()] T [int(i) for i in input().split()] [0 for j in range(M)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [0 for j in range(M)] dp=[[0 for j in range(M)] for i in range(N)] dp [[0 for j in range(M)] for i in range(N)] [0 for j in range(M+1)] for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [0 for j in range(M+1)] ans=[[0 for j in range(M+1)] for i in range(N+1)] ans [[0 for j in range(M+1)] for i in range(N+1)] for i in range(N+1):
    ans[i][0]=1 i range(N+1) range N+1 N 1 ans[i][0]=1 ans[i][0] [i] ans i 0 1 for j in range(M+1):
    ans[0][j]=1 j range(M+1) range M+1 M 1 ans[0][j]=1 ans[0][j] [0] ans 0 j 1 for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j]=ans[i][j]
        else:
            dp[i][j]=0
        ans[i+1][j+1]=dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j]
        ans[i+1][j+1]%=mod i range(N) range N for j in range(M):
        if S[i]==T[j]:
            dp[i][j]=ans[i][j]
        else:
            dp[i][j]=0
        ans[i+1][j+1]=dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j]
        ans[i+1][j+1]%=mod j range(M) range M if S[i]==T[j]:
            dp[i][j]=ans[i][j]
        else:
            dp[i][j]=0
         S[i]==T[j] S[i] S i T[j] T j dp[i][j]=ans[i][j] dp[i][j] [i] dp i j ans[i][j] [i] ans i j dp[i][j]=0 dp[i][j] [i] dp i j 0 ans[i+1][j+1]=dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j] ans[i+1][j+1] [i+1] ans i+1 i 1 j+1 j 1 dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j] dp[i][j]+ans[i+1][j]+ans[i][j+1] dp[i][j]+ans[i+1][j] dp[i][j] [i] dp i j ans[i+1][j] [i+1] ans i+1 i 1 j ans[i][j+1] [i] ans i j+1 j 1 ans[i][j] [i] ans i j ans[i+1][j+1]%=mod ans[i+1][j+1] [i+1] ans i+1 i 1 j+1 j 1 mod print(ans[N][M]) print ans[N][M] [N] ans N M T=[int(i) for i in input().split()] [int(i) for i in input().split()] T N,M=map(int,input().split()) map(int,input().split()) N S=[int(i) for i in input().split()] [int(i) for i in input().split()] S M=map(int,input().split()) map(int,input().split()) M ans=[[0 for j in range(M+1)] for i in range(N+1)] [[0 for j in range(M+1)] for i in range(N+1)] ans mod=10**9+7 10**9+7 mod dp=[[0 for j in range(M)] for i in range(N)] [[0 for j in range(M)] for i in range(N)] dp
mod=10**9+7
N,M=map(int,input().split())
S=[int(i) for i in input().split()]
T=[int(i) for i in input().split()]
dp=[[0 for j in range(M)] for i in range(N)]
ans=[[0 for j in range(M+1)] for i in range(N+1)]
for i in range(N+1):
    ans[i][0]=1
for j in range(M+1):
    ans[0][j]=1
for i in range(N):
    for j in range(M):
        if S[i]==T[j]:
            dp[i][j]=ans[i][j]
        else:
            dp[i][j]=0
        ans[i+1][j+1]=dp[i][j]+ans[i+1][j]+ans[i][j+1]-ans[i][j]
        ans[i+1][j+1]%=mod
print(ans[N][M])
