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