n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod = 10**9+7
dp = [[0 for j in range(m)]for i in range(n)]
for i in range(m):
    if s[0] ==t[i]:
        dp[0][i] = 1
for i in range(n):
    if s[i] ==t[0]:
        dp[i][0] = 1

for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            sumdp = 0
            for k in range(i):
                for l in range(j):
                    sumdp += dp[k][l]
            dp[i][j] = (sumdp + 1) % mod
res = 1
for i in range(n):
    for j in range(m):
        res += dp[i][j]
        res %= mod
print(res)