import numpy as np

N,M = map(int,input().split())
MOD = 1e9 + 7
S = np.array(input().split())
T = np.array(input().split())

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

for n in range(1,N+1):
    same = (T == S[n-1])
    dp[n,1:][same] = dp[n-1,:-1][same]
    dp[n] = (dp[n].cumsum() + dp[n-1])%MOD
    
print(int(dp[N,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 MOD = 1e9 + 7 MOD 1e9 + 7 1e9 7 S = np.array(input().split()) S np.array(input().split()) np.array np array input().split() ().split () input split T = np.array(input().split()) T np.array(input().split()) np.array np array input().split() ().split () input split dp = np.zeros((N+1,M+1)) dp np.zeros((N+1,M+1)) np.zeros np zeros (N+1,M+1) N+1 N 1 M+1 M 1 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]
    dp[n] = (dp[n].cumsum() + dp[n-1])%MOD
     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 print(int(dp[N,M])) print int(dp[N,M]) int dp[N,M] dp N M = map(int,input().split()) map(int,input().split()) M same = (T == S[n-1]) T == S[n-1] same T = np.array(input().split()) np.array(input().split()) T dp = np.zeros((N+1,M+1)) np.zeros((N+1,M+1)) dp N,M = map(int,input().split()) map(int,input().split()) N S = np.array(input().split()) np.array(input().split()) S MOD = 1e9 + 7 1e9 + 7 MOD
import numpy as np

N,M = map(int,input().split())
MOD = 1e9 + 7
S = np.array(input().split())
T = np.array(input().split())

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

for n in range(1,N+1):
    same = (T == S[n-1])
    dp[n,1:][same] = dp[n-1,:-1][same]
    dp[n] = (dp[n].cumsum() + dp[n-1])%MOD
    
print(int(dp[N,M]))