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)) for _ in range(len(S))]

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

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