import sys
from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle

# from functools import reduce
# from math import ceil, floor, log10, log2, factorial

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]


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

DP = [[0] * (M + 1) for _ in range(N + 1)]
DP[0][0] = 1
for n in range(N + 1):
    for m in range(M + 1):
        if n > 0 and m > 0 and S[n - 1] == T[m - 1]:
            for nn in range(n):
                for mm in range(m):
                    DP[n][m] += DP[nn][mm]

print(sum(sum(DP, [])) % MOD)
