import numpy as np

N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = np.array(list(map(int, input().split())))

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

for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % (10**9+7)
print(dp[-1]) import numpy as np numpy N, M = list(map(int, input().split())) N list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split M S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = np.array(list(map(int, input().split()))) T np.array(list(map(int, input().split()))) np.array np array list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split dp = np.ones(M+1, dtype='int64') dp np.ones(M+1, dtype='int64') np.ones np ones M+1 M 1 dtype='int64' dtype 'int64' for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % (10**9+7) s S dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % (10**9+7) dp[1:] dp 1: 1 ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % (10**9+7) (dp[:-1] * (s == T)).cumsum() + dp[1:] (dp[:-1] * (s == T)).cumsum() dp[:-1] * (s == T)).cumsum dp[:-1] * (s == T) dp[:-1] dp :-1 -1 s == T s T cumsum dp[1:] dp 1: 1 10**9+7 10**9 10 9 7 print(dp[-1]) print dp[-1] dp -1 N, M = list(map(int, input().split())) list(map(int, input().split())) N M = list(map(int, input().split())) list(map(int, input().split())) M dp = np.ones(M+1, dtype='int64') np.ones(M+1, dtype='int64') dp T = np.array(list(map(int, input().split()))) np.array(list(map(int, input().split()))) T S = list(map(int, input().split())) list(map(int, input().split())) S
import numpy as np

N, M = list(map(int, input().split()))
S = list(map(int, input().split()))
T = np.array(list(map(int, input().split())))

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

for s in S:
    dp[1:] = ((dp[:-1] * (s == T)).cumsum() + dp[1:]) % (10**9+7)
print(dp[-1])