import numpy as np
import sys
input = sys.stdin.readline

MOD = 10**9 + 7
N,M = 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 numpy import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 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.zeros((N+1, M+1), dtype = np.int64) dp np.zeros((N+1, M+1), dtype = np.int64) np.zeros np zeros (N+1, M+1) N+1 N 1 M+1 M 1 dtype = np.int64 dtype np.int64 np int64 dp[0] = 1 dp[0] 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に直す n range(1, N+1) range 1 N+1 N 1 same = (T == S[n-1]) same T == S[n-1] T S[n-1] S n-1 n 1 dp[n,1:][same] = dp[n-1,:-1][same] dp[n,1:][same] [n,1:] dp n same dp[n-1,:-1][same] [n-1,:-1] dp n-1 n 1 same dp[n] = (dp[n].cumsum() + dp[n-1]) % MOD dp[n] dp n (dp[n].cumsum() + dp[n-1]) % MOD dp[n].cumsum() + dp[n-1] dp[n].cumsum() [n].cumsum [n] dp n cumsum dp[n-1] dp n-1 n 1 MOD answer = dp[N,M] answer dp[N,M] dp N print(answer) print answer same = (T == S[n-1]) T == S[n-1] same answer = dp[N,M] dp[N,M] answer dp = np.zeros((N+1, M+1), dtype = np.int64) np.zeros((N+1, M+1), dtype = np.int64) dp T = np.array(input().split(), dtype=np.int32) np.array(input().split(), dtype=np.int32) T input = sys.stdin.readline sys.stdin.readline input M = map(int,input().split()) map(int,input().split()) M S = np.array(input().split(), dtype=np.int32) np.array(input().split(), dtype=np.int32) S MOD = 10**9 + 7 10**9 + 7 MOD N,M = map(int,input().split()) map(int,input().split()) N
import numpy as np
import sys
input = sys.stdin.readline

MOD = 10**9 + 7
N,M = 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)
