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

tempArray = [1]*(M + 1)
for i, x in enumerate(S):
  tempArray2 = tempArray[:]
  k = 0
  for j, y in enumerate(T):
    if x == y:
      k += tempArray[j]
    tempArray2[j + 1] = tempArray[j + 1] + k
  tempArray = tempArray2
print(tempArray[-1])