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