N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

A = [[1]*(M+1) for i in range(N+1)]
for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            A[i+1][j+1] = (A[i+1][j] + A[i][j+1])%mod
        else:
            A[i+1][j+1] = (A[i+1][j] + A[i][j+1] - A[i][j])%mod
print(A[N][M])

