MOD = 1000000007
n, m = list(map(int, input.split()))
a = list(map(int, input.split()))
b = list(map(int, input.split()))
f = [[0] * (m + 1)]
for i in range(n):
  f.append([0] * (m + 1))
for i in range(1, n + 1):
  for j in range(1, m + 1):
    f[i][j] = (f[i - 1][j] + f[i][j - 1]) % MOD
    if a[i - 1] != b[j - 1]:
      f[i][j] = (f[i][j] + MOD - f[i - 1][j - 1]) % MOD
print(f[n][m])