import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

n,m = m()

S = l()
T = l()

dp = [ [0 for i in range(n+1)]  for j in range(m+1)]

for i in range(n+1):
    dp[0][i] = 1
for i in range(m+1):
    dp[i][0] = 1

for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            dp[j+1][i+1] += dp[j][i]
        dp[j+1][i+1] +=dp[j+1][i] + dp[j][i+1] - dp[j][i]
        dp[j+1][i+1] %= 10**9+7
print(dp[-1][-1])
 import sys,collections as cl,bisect as bs sys collections bisect sys.setrecursionlimit(100000) sys.setrecursionlimit sys setrecursionlimit 100000 Max = sys.maxsize Max sys.maxsize sys maxsize def l():
    return list(map(int,input().split())) l return list(map(int,input().split())) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split def m():
    return map(int,input().split()) m return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def onem():
    return int(input()) onem return int(input()) int(input()) int input() input def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a s a = [] a [] aa = x[0] aa x[0] x 0 su = 1 su 1 for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
     i range(len(x)-1) range len(x)-1 len(x) len x 1 if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
     aa == x[i+1] aa x[i+1] x i+1 i 1 a.append([aa,su]) a.append a append [aa,su] aa su aa = x[i+1] aa x[i+1] x i+1 i 1 su = 1 su 1 su += 1 su 1 a.append([aa,su]) a.append a append [aa,su] aa su return a a x x def jo(x):
    return " ".join(map(str,x)) jo return " ".join(map(str,x)) " ".join(map(str,x)) " ".join " " join map(str,x) map str x x x n,m = m() n m() m m S = l() S l() l T = l() T l() l [0 for i in range(n+1)]  for j in range(m+1) for j in range(m+1) j range(m+1) range m+1 m 1 for j in range(m+1) [0 for i in range(n+1)] dp = [ [0 for i in range(n+1)]  for j in range(m+1)] dp [ [0 for i in range(n+1)]  for j in range(m+1)] for i in range(n+1):
    dp[0][i] = 1 i range(n+1) range n+1 n 1 dp[0][i] = 1 dp[0][i] [0] dp 0 i 1 for i in range(m+1):
    dp[i][0] = 1 i range(m+1) range m+1 m 1 dp[i][0] = 1 dp[i][0] [i] dp i 0 1 for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            dp[j+1][i+1] += dp[j][i]
        dp[j+1][i+1] +=dp[j+1][i] + dp[j][i+1] - dp[j][i]
        dp[j+1][i+1] %= 10**9+7 i range(n) range n for j in range(m):
        if S[i] == T[j]:
            dp[j+1][i+1] += dp[j][i]
        dp[j+1][i+1] +=dp[j+1][i] + dp[j][i+1] - dp[j][i]
        dp[j+1][i+1] %= 10**9+7 j range(m) range m if S[i] == T[j]:
            dp[j+1][i+1] += dp[j][i]
         S[i] == T[j] S[i] S i T[j] T j dp[j+1][i+1] += dp[j][i] dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 dp[j][i] [j] dp j i dp[j+1][i+1] +=dp[j+1][i] + dp[j][i+1] - dp[j][i] dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 dp[j+1][i] + dp[j][i+1] - dp[j][i] dp[j+1][i] + dp[j][i+1] dp[j+1][i] [j+1] dp j+1 j 1 i dp[j][i+1] [j] dp j i+1 i 1 dp[j][i] [j] dp j i dp[j+1][i+1] %= 10**9+7 dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 10**9+7 10**9 10 9 7 print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 def m():
    return map(int,input().split()) def m():
    return map(int,input().split()) m def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a s Max = sys.maxsize sys.maxsize Max m = m() m() m S = l() l() S dp = [ [0 for i in range(n+1)]  for j in range(m+1)] [ [0 for i in range(n+1)]  for j in range(m+1)] dp def jo(x):
    return " ".join(map(str,x)) def jo(x):
    return " ".join(map(str,x)) jo T = l() l() T n,m = m() m() n def l():
    return list(map(int,input().split())) def l():
    return list(map(int,input().split())) l def onem():
    return int(input()) def onem():
    return int(input()) onem
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
    return list(map(int,input().split()))
def m():
    return map(int,input().split())
def onem():
    return int(input())
def s(x):
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa == x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x):
    return " ".join(map(str,x))

n,m = m()

S = l()
T = l()

dp = [ [0 for i in range(n+1)]  for j in range(m+1)]

for i in range(n+1):
    dp[0][i] = 1
for i in range(m+1):
    dp[i][0] = 1

for i in range(n):
    for j in range(m):
        if S[i] == T[j]:
            dp[j+1][i+1] += dp[j][i]
        dp[j+1][i+1] +=dp[j+1][i] + dp[j][i+1] - dp[j][i]
        dp[j+1][i+1] %= 10**9+7
print(dp[-1][-1])

