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

data=[[0 for i in range(0,M)] for j in range(0,N)]
for i in range(0,N):
    if S[i]==T[0]:
        data[i][0]=1

dp=[[1 for i in range(0,M)] for j in range(0,N)]
for j in range(0,M):
    if j==0:
        if S[0]==T[0]:
            dp[0][0]=2
    else:
        if S[0]==T[j]:
            dp[0][j]=(dp[0][j-1]+1)%(10**9+7)
        else:
            dp[0][j]=dp[0][j-1]%(10**9+7)

for i in range(0,N):
    for j in range(0,M):
        if j!=0:
            if S[i]==T[j]:
                data[i][j]=(data[i][j-1]+dp[i-1][j-1])%(10**9+7)
            else:
                data[i][j]=data[i][j-1]
        if i!=0:
            dp[i][j]=(dp[i-1][j]+data[i][j])%(10**9+7)

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

data=[[0 for i in range(0,M)] for j in range(0,N)]
for i in range(0,N):
    if S[i]==T[0]:
        data[i][0]=1

dp=[[1 for i in range(0,M)] for j in range(0,N)]
for j in range(0,M):
    if j==0:
        if S[0]==T[0]:
            dp[0][0]=2
    else:
        if S[0]==T[j]:
            dp[0][j]=(dp[0][j-1]+1)%(10**9+7)
        else:
            dp[0][j]=dp[0][j-1]%(10**9+7)

for i in range(0,N):
    for j in range(0,M):
        if j!=0:
            if S[i]==T[j]:
                data[i][j]=(data[i][j-1]+dp[i-1][j-1])%(10**9+7)
            else:
                data[i][j]=data[i][j-1]
        if i!=0:
            dp[i][j]=(dp[i-1][j]+data[i][j])%(10**9+7)

print(dp[N-1][M-1]%(10**9+7))