n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
mod = 10**9+7
dp = [[0 for j in range(m)]for i in range(n)]
for i in range(m):
    if s[0] ==t[i]:
        dp[0][i] = 1
for i in range(n):
    if s[i] ==t[0]:
        dp[i][0] = 1

sumdp = [[0 for j in range(m)]for i in range(n)]
if s[0] ==t[0]:
    sumdp[0][0] =1
for i in range(m-1):
    sumdp[0][i+1] =sumdp[0][i]
    if s[0] == t[i+1]:
        sumdp[0][i+1] += 1
for i in range(n-1):
    sumdp[i+1][0]=sumdp[i][0]
    if s[i+1] ==t[0]:
        sumdp[i+1][0] += 1

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

sumdp = [[0 for j in range(m)]for i in range(n)]
if s[0] ==t[0]:
    sumdp[0][0] =1
for i in range(m-1):
    sumdp[0][i+1] =sumdp[0][i]
    if s[0] == t[i+1]:
        sumdp[0][i+1] += 1
for i in range(n-1):
    sumdp[i+1][0]=sumdp[i][0]
    if s[i+1] ==t[0]:
        sumdp[i+1][0] += 1

for i in range(n-1):
    for j in range(m-1):
        if s[i+1] == t[j+1]:
            dp[i+1][j+1] = (sumdp[i][j] + 1) % mod
        sumdp[i+1][j+1] = (sumdp[i][j+1]+sumdp[i+1][j] - sumdp[i][j]+dp[i+1][j+1])%mod
print((sumdp[n-1][m-1]+1)%mod)