N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10 ** 9 + 7

dp = [[0 for _ in range(M)] for _ in range(N)]
dp[0][0] = 1

for i in range(N):
  for j in range(M):
    if i == j == 0:
      continue
    if S[i] == T[j]:
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + 1) % MOD
    else:
      dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])
      
print(dp[-1][-1] + 1)