MOD = 10 ** 9 + 7

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

dp_sum = [0] * (M + 1)

for i in range(N):
    for j in range(M):
        if S[i] == T[j]:
            dp_sum[j + 1] += dp_sum[j] + 1
        else:
            dp_sum[j + 1] = dp_sum[j]

print((dp_sum[M] + 1) % MOD)
