MOD = 10 ** 9 + 7


def main(S, T):
  sdp = [[0] * (len(T) + 1) for _ in range(len(S) + 1)]

  for i, s in enumerate(S):
    for j, t in enumerate(T):
      v = sdp[i][j + 1] + sdp[i + 1][j] + (1 if s == t else -sdp[i][j])
      sdp[i + 1][j + 1] = v % MOD

  return (sdp[-1][-1] + 1)


if __name__ == '__main__':
  _, _ = map(int, input().strip().split())
  S = input().strip().split()
  T = input().strip().split()
  # S = range(1000)
  # T = range(1000)
  print(main(S, T))