import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

n, m = LI()
ss = LI()
ts = LI()
ans += 1

dp = [[0 for _ in range(m)] for _ in range(n)]
dp2 = [[0 for _ in range(m)] for _ in range(n)]

for i in range(n):
    for j in range(m):
        dp[i][j] = 1 if ss[i] == ts[j] else 0

index_d = defaultdict(list)

for i in range(n):
    for j in range(m):
        if i != 0:
            x = dp[n-i+1][n-j] 
        else:
            x = 0
        if j != 0:
            y = dp[n-i][n-j+1] 
        else:
            y = 0
        dp[n-i][n-j] = dp[n-i][n-j] + x + y
print((dp[0][0] + 1) % MOD)


