from math import factorial

n, m = map(int, input().split(" "))
s = list(map(int, input().split(" ")))
t = list(map(int, input().split(" ")))

dp = [[0] * m for i in s]

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

# print(dp)
r = sum(sum(x) for x in dp)
print((r + 1) % (1000000007))
