nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M = nl()
S = nl()
T = nl()

import numpy as np
dp = np.zeros((N+1, M+1), dtype=np.uint32)
for i in range(1, N+1):
    for j in range(1, M+1):
        dp[i, j] += dp[i-1, j] + dp[i, j-1]
        if S[i-1] == T[j-1]:
            dp[i, j] += 1
        else:
            dp[i, j] -= dp[i-1, j-1]
        dp[i, j] %= 1000000007

print(int(dp[N, M]+1))
