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

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

print(dp[M])