#解説読み 2次元dp
mod = 10**9 + 7
n,m = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
tmp = [1 for _ in range(m+1)]
dp = [tmp]
for ni in range(n):
  last = tmp
  tmp = [1]
  for mi in range(m):
    if A[ni] != B[mi]:
      x = tmp[-1]+last[mi+1]-last[mi]
    else:
      x = tmp[-1]+last[mi+1]
    x %= mod
    tmp.append(x)
  dp.append(tmp)
print(dp[-1][-1])