MOD = 10 ** 9 + 7

_, _ = map(int, input().strip().split())
S = list(map(int, input().strip().split()))
T = list(map(int, 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] + (1 if s == t else -sdp[i][j])
    sdp[i + 1][j + 1] = v % MOD

print(sdp[-1][-1] + 1)
# for row in sdp:
#  print(('{: 4d} ' * len(row)).format(*row))
## print(sdp)