N,M = map(int,input().split())
S = [int(x) for x in input().split()]
T = [int(x) for x in input().split()]

ans = [0 for i in range(M)]

for i in range(N):
    indexes = [j for j, x in enumerate(T) if x == S[i]]
    for ind in indexes[::-1]:
        ans[ind] += 1 + sum(ans[:ind])

print((sum(ans)+1)%(1000000007))