n, m = map(int, input().split())
s = list(map(int, input().split())) + [0]
t = list(map(int, input().split())) + [0]
MOD = 10 ** 9 + 7
dp = [[0 for j in range(m + 2)] for i in range(n + 2)]
sumdp = [[0 for j in range(m + 2)] for i in range(n + 2)]
for i, si in enumerate(s):
    for j, tj in enumerate(t):
        if si == tj:
            dp[i + 1][j + 1] = (sumdp[i][j] + 1) % MOD
        sumdp[i + 1][j + 1] = (sumdp[i + 1][j] + sumdp[i][j + 1] - sumdp[i][j] + dp[i + 1][j + 1]) % MOD
print(dp[-1][-1])
