from collections import defaultdict

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

for i in range(N):
    for j in range(M):
        temp = 0
        if(S[i] == T[j]):
            temp = sum_dp[(i-1, j-1)] + 1
        sum_dp[(i, j)] = sum_dp[(i-1, j)] + sum_dp[(i, j-1)] - sum_dp[(i-1, j-1)] + temp
        sum_dp[(i, j)] %= mod

print(sum_dp[(N-1, M-1)] + 1)
