#  --*-coding:utf-8-*--

MOD = 10**9+7

N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))

X = [0]*(N+1)
X[0] = 1

for t in T:
    Y = X[:]
    x = 1
    
    for i, s in enumerate(S):
        if t == s:
            Y[i+1] += x

        x += X[i+1]
        x %= MOD

    X = Y

print(sum(Y)%MOD)
