import numpy as np

n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10**9 + 7

dp = np.zeros(shape=(n, m))

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            if i == 0:
                dp[i, j] = sum(dp[:i, :j]) + 1
            else:
                dp[i, j] = sum(sum(dp[:i, :j])) + 1
        else:
            dp[i, j] = 0

print(int((sum(sum(dp)) + 1) % mod))