import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
ans = int(0)

N, M = LI()
S = LI()
T = LI()
dp = [[0]*(M+1) for _ in range(N+1)]
sumdp = [[0]*(M+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %=mod
#        ans += dp[i][j]
#print(dp)
#for row in dp:
#    ans+= sum(row)%mod
print((sumdp[N][M]+1)%mod) import sys sys def I(): return int(sys.stdin.readline()) I def LI(): return list(map(int,sys.stdin.readline().split())) LI mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 ans = int(0) ans int(0) int 0 N, M = LI() N LI() LI M S = LI() S LI() LI T = LI() T LI() LI [0]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 dp = [[0]*(M+1) for _ in range(N+1)] dp [[0]*(M+1) for _ in range(N+1)] [0]*(M+1) for _ in range(N+1) for _ in range(N+1) _ range(N+1) range N+1 N 1 for _ in range(N+1) [0]*(M+1) [0] 0 M+1 M 1 sumdp = [[0]*(M+1) for _ in range(N+1)] sumdp [[0]*(M+1) for _ in range(N+1)] for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %=mod
#        ans += dp[i][j]
#print(dp)
#for row in dp:
#    ans+= sum(row)%mod i range(1,N+1) range 1 N+1 N 1 for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %=mod
#        ans += dp[i][j]
#print(dp)
#for row in dp:
#    ans+= sum(row)%mod j range(1,M+1) range 1 M+1 M 1 if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
         S[i-1]==T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 dp[i][j] = sumdp[i-1][j-1]+1 dp[i][j] [i] dp i j sumdp[i-1][j-1]+1 sumdp[i-1][j-1] [i-1] sumdp i-1 i 1 j-1 j 1 1 sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1 sumdp[i][j] [i] sumdp i j sumdp[i - 1][j] + sumdp[i][j - 1] +1 sumdp[i - 1][j] + sumdp[i][j - 1] sumdp[i - 1][j] [i - 1] sumdp i - 1 i 1 j sumdp[i][j - 1] [i] sumdp i j - 1 j 1 1 sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] sumdp[i][j] [i] sumdp i j sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] sumdp[i-1][j] + sumdp[i][j-1] sumdp[i-1][j] [i-1] sumdp i-1 i 1 j sumdp[i][j-1] [i] sumdp i j-1 j 1 sumdp[i-1][j-1] [i-1] sumdp i-1 i 1 j-1 j 1 sumdp[i][j] %=mod sumdp[i][j] [i] sumdp i j mod print((sumdp[N][M]+1)%mod) print (sumdp[N][M]+1)%mod sumdp[N][M]+1 sumdp[N][M] [N] sumdp N M 1 mod S = LI() LI() S ans = int(0) int(0) ans def LI(): return list(map(int,sys.stdin.readline().split())) def LI(): return list(map(int,sys.stdin.readline().split())) LI dp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] dp def I(): return int(sys.stdin.readline()) def I(): return int(sys.stdin.readline()) I mod = 10**9 + 7 10**9 + 7 mod M = LI() LI() M T = LI() LI() T N, M = LI() LI() N sumdp = [[0]*(M+1) for _ in range(N+1)] [[0]*(M+1) for _ in range(N+1)] sumdp
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
ans = int(0)

N, M = LI()
S = LI()
T = LI()
dp = [[0]*(M+1) for _ in range(N+1)]
sumdp = [[0]*(M+1) for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(1,M+1):
        if S[i-1]==T[j-1]:
            dp[i][j] = sumdp[i-1][j-1]+1
            sumdp[i][j] = sumdp[i - 1][j] + sumdp[i][j - 1] +1
#            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1] + dp[i][j]
        #累積和の更新
        else:
            sumdp[i][j] = sumdp[i-1][j] + sumdp[i][j-1] - sumdp[i-1][j-1]
        sumdp[i][j] %=mod
#        ans += dp[i][j]
#print(dp)
#for row in dp:
#    ans+= sum(row)%mod
print((sumdp[N][M]+1)%mod)