import numpy as np

import sys

input = sys.stdin.readline



MOD = 10**9 + 7

N,M = list(map(int,input().split()))

S = np.array(input().split(), dtype=np.int32)

T = np.array(input().split(), dtype=np.int32)



# (n,m) 以前で作れている列

dp = np.zeros((N+1, M+1), dtype = np.int64)

dp[0] = 1



for n in range(1, N+1):

  same = (T == S[n-1])

  dp[n,1:][same] = dp[n-1,:-1][same] # ちょうど(n,m)で終わる

  dp[n] = (dp[n].cumsum() + dp[n-1]) % MOD # cumsumに直す



answer = dp[N,M]

print(answer)

import numpy as np

MOD = 10**9 + 7

N,M = list(map(int,input().split()))

S = np.array(input().split(), dtype=np.int32)

T = np.array(input().split(), dtype=np.int32)



# (n,m) 以前で作れている列

dp = np.ones(M+1, dtype = np.int64)



for n in range(N):

  dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD # cumsumに直す



answer = dp[M]

print(answer)
import numpy as np
import sys

input = sys.stdin.readline
MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.zeros((N + 1, M + 1), dtype=np.int64)
dp[0] = 1
for n in range(1, N + 1):
    same = T == S[n - 1]
    dp[n, 1:][same] = dp[n - 1, :-1][same]  # ちょうど(n,m)で終わる
    dp[n] = (dp[n].cumsum() + dp[n - 1]) % MOD  # cumsumに直す
answer = dp[N, M]
print(answer)

import numpy as np

MOD = 10**9 + 7
N, M = list(map(int, input().split()))
S = np.array(input().split(), dtype=np.int32)
T = np.array(input().split(), dtype=np.int32)
# (n,m) 以前で作れている列
dp = np.ones(M + 1, dtype=np.int64)
for n in range(N):
    dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD  # cumsumに直す
answer = dp[M]
print(answer)

-import sys -input = sys.stdin.readline -dp = np.zeros((N + 1, M + 1), dtype=np.int64) -dp[0] = 1 -for n in range(1, N + 1): -    same = T == S[n - 1] -    dp[n, 1:][same] = dp[n - 1, :-1][same]  # ちょうど(n,m)で終わる -    dp[n] = (dp[n].cumsum() + dp[n - 1]) % MOD  # cumsumに直す -answer = dp[N, M] +dp = np.ones(M + 1, dtype=np.int64) +for n in range(N): +    dp[1:] = ((dp[:-1] * (T == S[n])).cumsum() + dp[1:]) % MOD  # cumsumに直す +answer = dp[M]