from collections import defaultdict

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

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

# S -> T
relation_list = []
for s in S:
    buffer = []
    for j, t in enumerate(T):
        if t == s:
            buffer.append(j)
    relation_list.append(buffer)

pattern = defaultdict(int)

for relation in relation_list[::-1]:
    for j in relation:
        pattern[j] += sum([value for key, value in pattern.items() if key > j]) + 1

print((sum(pattern.values()) + 1)%(10**9+7))