N,M = list(map(int,input().split()))

S = list(map(int,input().split()))
T = list(map(int,input().split()))

DP = [[0]*(N+1) for i in range(M+1)]

for i in range(N+1):
    DP[0][i]=1


for i in range(M+1):
    DP[i][0]=1

mod=10**9 + 7
for i in range(M):
    for j in range(N):
        if T[i]==S[j]:
            DP[i+1][j+1]=(DP[i+1][j]+DP[i][j+1])%mod
        else:
            DP[i+1][j+1]=(DP[i+1][j]+DP[i][j+1]-DP[i][j])%mod

print(DP[M][N])