N,M= map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=10**9+7
ans=[[0 for e in range(M)] for f in range(N)]
rui=[[0 for e in range(M)] for f in range(N)]
for j in range(M):
 if j!=0:
  rui[0][j]=rui[0][j-1]
 if S[0]==T[j]:
  ans[0][j]=1
  rui[0][j]+=ans[0][j]
for i in range(1,N):
 rui[i][0]=rui[i-1][0]
 if S[i]==T[0]:
  ans[i][0]=1
  rui[i][0]+=ans[i][0]
for i in range(1,N):
 for j in range(1,M):
  rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1]
  if S[i]==T[j]:
   ans[i][j]=(rui[i-1][j-1]+1)
   rui[i][j]+=ans[i][j]
  rui[i][j]%=mod
print((rui[N-1][M-1]+1)%mod) 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 mod=10**9+7 mod 10**9+7 10**9 10 9 7 [0 for e in range(M)] for f in range(N) for f in range(N) f range(N) range N for f in range(N) [0 for e in range(M)] ans=[[0 for e in range(M)] for f in range(N)] ans [[0 for e in range(M)] for f in range(N)] [0 for e in range(M)] for f in range(N) for f in range(N) f range(N) range N for f in range(N) [0 for e in range(M)] rui=[[0 for e in range(M)] for f in range(N)] rui [[0 for e in range(M)] for f in range(N)] for j in range(M):
 if j!=0:
  rui[0][j]=rui[0][j-1]
 if S[0]==T[j]:
  ans[0][j]=1
  rui[0][j]+=ans[0][j] j range(M) range M if j!=0:
  rui[0][j]=rui[0][j-1]
  j!=0 j 0 rui[0][j]=rui[0][j-1] rui[0][j] [0] rui 0 j rui[0][j-1] [0] rui 0 j-1 j 1 if S[0]==T[j]:
  ans[0][j]=1
  rui[0][j]+=ans[0][j] S[0]==T[j] S[0] S 0 T[j] T j ans[0][j]=1 ans[0][j] [0] ans 0 j 1 rui[0][j]+=ans[0][j] rui[0][j] [0] rui 0 j ans[0][j] [0] ans 0 j for i in range(1,N):
 rui[i][0]=rui[i-1][0]
 if S[i]==T[0]:
  ans[i][0]=1
  rui[i][0]+=ans[i][0] i range(1,N) range 1 N rui[i][0]=rui[i-1][0] rui[i][0] [i] rui i 0 rui[i-1][0] [i-1] rui i-1 i 1 0 if S[i]==T[0]:
  ans[i][0]=1
  rui[i][0]+=ans[i][0] S[i]==T[0] S[i] S i T[0] T 0 ans[i][0]=1 ans[i][0] [i] ans i 0 1 rui[i][0]+=ans[i][0] rui[i][0] [i] rui i 0 ans[i][0] [i] ans i 0 for i in range(1,N):
 for j in range(1,M):
  rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1]
  if S[i]==T[j]:
   ans[i][j]=(rui[i-1][j-1]+1)
   rui[i][j]+=ans[i][j]
  rui[i][j]%=mod i range(1,N) range 1 N for j in range(1,M):
  rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1]
  if S[i]==T[j]:
   ans[i][j]=(rui[i-1][j-1]+1)
   rui[i][j]+=ans[i][j]
  rui[i][j]%=mod j range(1,M) range 1 M rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1] rui[i][j] [i] rui i j rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1] rui[i][j-1]+rui[i-1][j] rui[i][j-1] [i] rui i j-1 j 1 rui[i-1][j] [i-1] rui i-1 i 1 j rui[i-1][j-1] [i-1] rui i-1 i 1 j-1 j 1 if S[i]==T[j]:
   ans[i][j]=(rui[i-1][j-1]+1)
   rui[i][j]+=ans[i][j]
   S[i]==T[j] S[i] S i T[j] T j ans[i][j]=(rui[i-1][j-1]+1) ans[i][j] [i] ans i j rui[i-1][j-1]+1 rui[i-1][j-1] [i-1] rui i-1 i 1 j-1 j 1 1 rui[i][j]+=ans[i][j] rui[i][j] [i] rui i j ans[i][j] [i] ans i j rui[i][j]%=mod rui[i][j] [i] rui i j mod print((rui[N-1][M-1]+1)%mod) print (rui[N-1][M-1]+1)%mod rui[N-1][M-1]+1 rui[N-1][M-1] [N-1] rui N-1 N 1 M-1 M 1 1 mod S=list(map(int,input().split())) list(map(int,input().split())) S mod=10**9+7 10**9+7 mod ans=[[0 for e in range(M)] for f in range(N)] [[0 for e in range(M)] for f in range(N)] ans T=list(map(int,input().split())) list(map(int,input().split())) T N,M= map(int,input().split()) map(int,input().split()) N rui=[[0 for e in range(M)] for f in range(N)] [[0 for e in range(M)] for f in range(N)] rui M= map(int,input().split()) map(int,input().split()) M
N,M= map(int,input().split())
S=list(map(int,input().split()))
T=list(map(int,input().split()))
mod=10**9+7
ans=[[0 for e in range(M)] for f in range(N)]
rui=[[0 for e in range(M)] for f in range(N)]
for j in range(M):
 if j!=0:
  rui[0][j]=rui[0][j-1]
 if S[0]==T[j]:
  ans[0][j]=1
  rui[0][j]+=ans[0][j]
for i in range(1,N):
 rui[i][0]=rui[i-1][0]
 if S[i]==T[0]:
  ans[i][0]=1
  rui[i][0]+=ans[i][0]
for i in range(1,N):
 for j in range(1,M):
  rui[i][j]=rui[i][j-1]+rui[i-1][j]-rui[i-1][j-1]
  if S[i]==T[j]:
   ans[i][j]=(rui[i-1][j-1]+1)
   rui[i][j]+=ans[i][j]
  rui[i][j]%=mod
print((rui[N-1][M-1]+1)%mod)