P = 10**9+7
N, M = map(int, input().split())
S = [int(a) for a in input().split()]
T = [int(a) for a in input().split()]
X = [[1] * (M+1)] + [[1]+[0]*M for _ in range(N)]
for i in range(N):
    for j in range(M):
        X[i+1][j+1] = (X[i+1][j] + X[i][j+1] - (X[i][j] * (S[i] != T[j])))%P
print(X[N][M])
