MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[[] for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
      
print(dp[N-1][M-1]) 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=list(map(int,input().split())) S list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split T=list(map(int,input().split())) T list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split [1]*(M+1) for i in range(N+1) for i in range(N+1) i range(N+1) range N+1 N 1 for i in range(N+1) [1]*(M+1) [1] 1 M+1 M 1 dp=[[1]*(M+1) for i in range(N+1)] dp [[1]*(M+1) for i in range(N+1)] [] for i in range(10**5+1) for i in range(10**5+1) i range(10**5+1) range 10**5+1 10**5 10 5 1 for i in range(10**5+1) [] S_index=[[] for i in range(10**5+1)] S_index [[] for i in range(10**5+1)] for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
       i range(N) range N S_index[S[i]].append(i) [S[i]].append [S[i]] S_index S[i] S i append i if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
   len(S_index[S[i]])>=2 len(S_index[S[i]]) len S_index[S[i]] S_index S[i] S i 2 ikkomae=S_index[S[i]][-2] ikkomae S_index[S[i]][-2] [S[i]] S_index S[i] S i -2 for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
   j range(M+1) range M+1 M 1 dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD dp[i-1][j] [i-1] dp i-1 i 1 j (dp[i-1][j]+dp[ikkomae-1][j])%MOD dp[i-1][j]+dp[ikkomae-1][j] dp[i-1][j] [i-1] dp i-1 i 1 j dp[ikkomae-1][j] [ikkomae-1] dp ikkomae-1 ikkomae 1 j MOD for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
       j range(M) range M dp[i][j]=dp[i][j-1] dp[i][j] [i] dp i j dp[i][j-1] [i] dp i j-1 j 1 if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
       len(S_index[T[j]])>=1 len(S_index[T[j]]) len S_index[T[j]] S_index T[j] T j 1 dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD dp[i][j] [i] dp i j (dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD dp[i][j]+dp[S_index[T[j]][-1]-1][j-1] dp[i][j] [i] dp i j dp[S_index[T[j]][-1]-1][j-1] [S_index[T[j]][-1]-1] dp S_index[T[j]][-1]-1 S_index[T[j]][-1] [T[j]] S_index T[j] T j -1 1 j-1 j 1 MOD print(dp[N-1][M-1]) print dp[N-1][M-1] [N-1] dp N-1 N 1 M-1 M 1 T=list(map(int,input().split())) list(map(int,input().split())) T dp=[[1]*(M+1) for i in range(N+1)] [[1]*(M+1) for i in range(N+1)] dp ikkomae=S_index[S[i]][-2] S_index[S[i]][-2] ikkomae S=list(map(int,input().split())) list(map(int,input().split())) S S_index=[[] for i in range(10**5+1)] [[] for i in range(10**5+1)] S_index N, M=map(int,input().split()) map(int,input().split()) N M=map(int,input().split()) map(int,input().split()) M MOD = 10**9+7 10**9+7 MOD
MOD = 10**9+7

N, M=map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))

dp=[[1]*(M+1) for i in range(N+1)]
S_index=[[] for i in range(10**5+1)]

for i in range(N):
  S_index[S[i]].append(i)
  if len(S_index[S[i]])>=2:
    ikkomae=S_index[S[i]][-2]
    for j in range(M+1):
    	dp[i-1][j]=(dp[i-1][j]+dp[ikkomae-1][j])%MOD
  for j in range(M):
    dp[i][j]=dp[i][j-1]
    if len(S_index[T[j]])>=1:
    	dp[i][j]=(dp[i][j]+dp[S_index[T[j]][-1]-1][j-1])%MOD
      
print(dp[N-1][M-1])
