MOD = 10 ** 9 + 7

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

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]
    if s == t:
      v += 1
    else:
      v -= sdp[i][j]
    sdp[i + 1][j + 1] = v % MOD

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