mo=10**9+7
n,m=map(int,input().split())
s=[0]+[int(i) for i in input().split()]
t=[0]+[int(i) for i in input().split()]
dp=[[0]*(1+n) for i in range(1+m)]
sm=[[0]*(1+n) for i in range(1+m)]

for i in range(1,1+m):
    if t[i]==s[1]:
        dp[i][1]=1
    sm[i][1]=sm[i-1][1]+dp[i][1]%mo

for i in range(1,1+n):
    if s[i]==t[1]:
        dp[1][i]=1
    sm[1][i]=sm[1][i-1]+dp[1][i]%mo

for i in range(2,1+m):
    for j in range(2,1+n):
        dp[i][j]=1+sm[i-1][j-1] if t[i]==s[j] else 0
        sm[i][j]=dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]
        sm[i][j]%=mo

print(1+sm[m][n]%mo) mo=10**9+7 mo 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 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=[0]+[int(i) for i in input().split()] s [0]+[int(i) for i in input().split()] [0] 0 [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=[0]+[int(i) for i in input().split()] t [0]+[int(i) for i in input().split()] [0] 0 [int(i) for i in input().split()] [0]*(1+n) for i in range(1+m) for i in range(1+m) i range(1+m) range 1+m 1 m for i in range(1+m) [0]*(1+n) [0] 0 1+n 1 n dp=[[0]*(1+n) for i in range(1+m)] dp [[0]*(1+n) for i in range(1+m)] [0]*(1+n) for i in range(1+m) for i in range(1+m) i range(1+m) range 1+m 1 m for i in range(1+m) [0]*(1+n) [0] 0 1+n 1 n sm=[[0]*(1+n) for i in range(1+m)] sm [[0]*(1+n) for i in range(1+m)] for i in range(1,1+m):
    if t[i]==s[1]:
        dp[i][1]=1
    sm[i][1]=sm[i-1][1]+dp[i][1]%mo i range(1,1+m) range 1 1+m 1 m if t[i]==s[1]:
        dp[i][1]=1
     t[i]==s[1] t[i] t i s[1] s 1 dp[i][1]=1 dp[i][1] [i] dp i 1 1 sm[i][1]=sm[i-1][1]+dp[i][1]%mo sm[i][1] [i] sm i 1 sm[i-1][1]+dp[i][1]%mo sm[i-1][1] [i-1] sm i-1 i 1 1 dp[i][1]%mo dp[i][1] [i] dp i 1 mo for i in range(1,1+n):
    if s[i]==t[1]:
        dp[1][i]=1
    sm[1][i]=sm[1][i-1]+dp[1][i]%mo i range(1,1+n) range 1 1+n 1 n if s[i]==t[1]:
        dp[1][i]=1
     s[i]==t[1] s[i] s i t[1] t 1 dp[1][i]=1 dp[1][i] [1] dp 1 i 1 sm[1][i]=sm[1][i-1]+dp[1][i]%mo sm[1][i] [1] sm 1 i sm[1][i-1]+dp[1][i]%mo sm[1][i-1] [1] sm 1 i-1 i 1 dp[1][i]%mo dp[1][i] [1] dp 1 i mo for i in range(2,1+m):
    for j in range(2,1+n):
        dp[i][j]=1+sm[i-1][j-1] if t[i]==s[j] else 0
        sm[i][j]=dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]
        sm[i][j]%=mo i range(2,1+m) range 2 1+m 1 m for j in range(2,1+n):
        dp[i][j]=1+sm[i-1][j-1] if t[i]==s[j] else 0
        sm[i][j]=dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]
        sm[i][j]%=mo j range(2,1+n) range 2 1+n 1 n dp[i][j]=1+sm[i-1][j-1] if t[i]==s[j] else 0 dp[i][j] [i] dp i j 1+sm[i-1][j-1] if t[i]==s[j] else 0 t[i]==s[j] t[i] t i s[j] s j 1+sm[i-1][j-1] 1 sm[i-1][j-1] [i-1] sm i-1 i 1 j-1 j 1 0 sm[i][j]=dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1] sm[i][j] [i] sm i j dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1] dp[i][j]+sm[i-1][j]+sm[i][j-1] dp[i][j]+sm[i-1][j] dp[i][j] [i] dp i j sm[i-1][j] [i-1] sm i-1 i 1 j sm[i][j-1] [i] sm i j-1 j 1 sm[i-1][j-1] [i-1] sm i-1 i 1 j-1 j 1 sm[i][j]%=mo sm[i][j] [i] sm i j mo print(1+sm[m][n]%mo) print 1+sm[m][n]%mo 1 sm[m][n]%mo sm[m][n] [m] sm m n mo s=[0]+[int(i) for i in input().split()] [0]+[int(i) for i in input().split()] s sm=[[0]*(1+n) for i in range(1+m)] [[0]*(1+n) for i in range(1+m)] sm n,m=map(int,input().split()) map(int,input().split()) n t=[0]+[int(i) for i in input().split()] [0]+[int(i) for i in input().split()] t mo=10**9+7 10**9+7 mo m=map(int,input().split()) map(int,input().split()) m dp=[[0]*(1+n) for i in range(1+m)] [[0]*(1+n) for i in range(1+m)] dp
mo=10**9+7
n,m=map(int,input().split())
s=[0]+[int(i) for i in input().split()]
t=[0]+[int(i) for i in input().split()]
dp=[[0]*(1+n) for i in range(1+m)]
sm=[[0]*(1+n) for i in range(1+m)]

for i in range(1,1+m):
    if t[i]==s[1]:
        dp[i][1]=1
    sm[i][1]=sm[i-1][1]+dp[i][1]%mo

for i in range(1,1+n):
    if s[i]==t[1]:
        dp[1][i]=1
    sm[1][i]=sm[1][i-1]+dp[1][i]%mo

for i in range(2,1+m):
    for j in range(2,1+n):
        dp[i][j]=1+sm[i-1][j-1] if t[i]==s[j] else 0
        sm[i][j]=dp[i][j]+sm[i-1][j]+sm[i][j-1]-sm[i-1][j-1]
        sm[i][j]%=mo

print(1+sm[m][n]%mo)