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))
wa = np.zeros(shape=(n, m))

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

print(int((wa[n-1, m-1] + 1) % mod))