N , M = map(int,input().split())

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

# 累積和参照のために0の行，列を追加
sm = [[0] * (M+1) for _ in range(N+1)]

for i , s in enumerate(S) :
    l1 = sm[i][:]
    l2 = 0
    for j , t in enumerate(T) :
        new = l1[j+1] + l2
        if s == t :
            new += 1  # dp = sm[i-1][j-1] + 1
        else :
            new -= l1[j] # dp = 0
        l2 = new
        sm[i+1][j+1] = new

ans = (sm[-1][-1] + 1) % (10**9 + 7)

print(ans)