import numpy as np
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)

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

for i in range(N):
  same = (s[i]==t)
  dp[i+1,1:][same] = dp[i,:-1][same]
  dp[i+1] = (dp[i+1].cumsum()+dp[i])%MOD

print(dp[-1,-1]) import numpy as np numpy 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 i in range(N):
  same = (s[i]==t)
  dp[i+1,1:][same] = dp[i,:-1][same]
  dp[i+1] = (dp[i+1].cumsum()+dp[i])%MOD i range(N) range N same = (s[i]==t) same s[i]==t s[i] s i t dp[i+1,1:][same] = dp[i,:-1][same] dp[i+1,1:][same] [i+1,1:] dp i+1 i 1 same dp[i,:-1][same] [i,:-1] dp i same dp[i+1] = (dp[i+1].cumsum()+dp[i])%MOD dp[i+1] dp i+1 i 1 (dp[i+1].cumsum()+dp[i])%MOD dp[i+1].cumsum()+dp[i] dp[i+1].cumsum() [i+1].cumsum [i+1] dp i+1 i 1 cumsum dp[i] dp i MOD print(dp[-1,-1]) print dp[-1,-1] dp -1 dp = np.zeros((N+1,M+1), dtype=np.int64) np.zeros((N+1,M+1), dtype=np.int64) dp MOD = 10**9+7 10**9+7 MOD same = (s[i]==t) s[i]==t same N, M = map(int, input().split()) map(int, input().split()) N 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 t = np.array(input().split(), dtype=np.int32) np.array(input().split(), dtype=np.int32) t
import numpy as np
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)

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

for i in range(N):
  same = (s[i]==t)
  dp[i+1,1:][same] = dp[i,:-1][same]
  dp[i+1] = (dp[i+1].cumsum()+dp[i])%MOD

print(dp[-1,-1])
