import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()
s = list(li())
t = list(li())

MOD = 10**9 + 7

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

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

print((dp[n][m] + 1) % MOD) import sys sys stdin = sys.stdin stdin sys.stdin sys stdin sys.setrecursionlimit(10 ** 7) sys.setrecursionlimit sys setrecursionlimit 10 ** 7 10 7 def li(): return map(int, stdin.readline().split()) li def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) li_ def lf(): return map(float, stdin.readline().split()) lf def ls(): return stdin.readline().split() ls def ns(): return stdin.readline().rstrip() ns def lc(): return list(ns()) lc def ni(): return int(stdin.readline()) ni def nf(): return float(stdin.readline()) nf n, m = li() n li() li m s = list(li()) s list(li()) list li() li t = list(li()) t list(li()) list li() li MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 [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)] for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD
        else:
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD i range(n) range n for j in range(m):
        if s[i] == t[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD
        else:
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD j range(m) range m if s[i] == t[j]:
            dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD
        else:
            dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD s[i] == t[j] s[i] s i t[j] t j dp[i+1][j+1] = (dp[i][j+1] + dp[i+1][j] + 1) % MOD dp[i+1][j+1] [i+1] dp i+1 i 1 j+1 j 1 (dp[i][j+1] + dp[i+1][j] + 1) % MOD dp[i][j+1] + dp[i+1][j] + 1 dp[i][j+1] + dp[i+1][j] dp[i][j+1] [i] dp i j+1 j 1 dp[i+1][j] [i+1] dp i+1 i 1 j 1 MOD dp[i + 1][j + 1] = (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD dp[i + 1][j + 1] [i + 1] dp i + 1 i 1 j + 1 j 1 (dp[i+1][j] + dp[i][j+1] - dp[i][j]) % MOD dp[i+1][j] + dp[i][j+1] - dp[i][j] dp[i+1][j] + dp[i][j+1] dp[i+1][j] [i+1] dp i+1 i 1 j dp[i][j+1] [i] dp i j+1 j 1 dp[i][j] [i] dp i j MOD print((dp[n][m] + 1) % MOD) print (dp[n][m] + 1) % MOD dp[n][m] + 1 dp[n][m] [n] dp n m 1 MOD MOD = 10**9 + 7 10**9 + 7 MOD def lf(): return map(float, stdin.readline().split()) def lf(): return map(float, stdin.readline().split()) lf t = list(li()) list(li()) t def li(): return map(int, stdin.readline().split()) def li(): return map(int, stdin.readline().split()) li dp = [[0]*(m+1) for _ in range(n+1)] [[0]*(m+1) for _ in range(n+1)] dp def ns(): return stdin.readline().rstrip() def ns(): return stdin.readline().rstrip() ns stdin = sys.stdin sys.stdin stdin def nf(): return float(stdin.readline()) def nf(): return float(stdin.readline()) nf m = li() li() m s = list(li()) list(li()) s n, m = li() li() n def lc(): return list(ns()) def lc(): return list(ns()) lc def ni(): return int(stdin.readline()) def ni(): return int(stdin.readline()) ni def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) def li_(): return map(lambda x: int(x) - 1, stdin.readline().split()) li_ def ls(): return stdin.readline().split() def ls(): return stdin.readline().split() ls
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n, m = li()
s = list(li())
t = list(li())

MOD = 10**9 + 7

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

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

print((dp[n][m] + 1) % MOD)
