MOD = pow(10, 9) + 7

n, m = map(int, input().split())
slist = list(map(int, input().split()))
tlist = list(map(int, input().split()))

dp = [[1 for _ in range(n+1)] for _ in range(m+1)]
for i, s in enumerate(slist):
  for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD

print(dp[-1][-1]) MOD = pow(10, 9) + 7 MOD pow(10, 9) + 7 pow(10, 9) pow 10 9 7 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m slist = list(map(int, input().split())) slist list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split tlist = list(map(int, input().split())) tlist list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [1 for _ in range(n+1)] for _ in range(m+1) for _ in range(m+1) _ range(m+1) range m+1 m 1 for _ in range(m+1) [1 for _ in range(n+1)] dp = [[1 for _ in range(n+1)] for _ in range(m+1)] dp [[1 for _ in range(n+1)] for _ in range(m+1)] for i, s in enumerate(slist):
  for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD i s enumerate(slist) enumerate slist for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD j t enumerate(tlist) enumerate tlist if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD s != t s t dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD (dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i] (dp[j+1][i] + dp[j][i+1]) % MOD dp[j+1][i] + dp[j][i+1] dp[j+1][i] [j+1] dp j+1 j 1 i dp[j][i+1] [j] dp j i+1 i 1 MOD dp[j][i] [j] dp j i MOD dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD dp[j+1][i+1] [j+1] dp j+1 j 1 i+1 i 1 (dp[j+1][i] + dp[j][i+1]) % MOD dp[j+1][i] + dp[j][i+1] dp[j+1][i] [j+1] dp j+1 j 1 i dp[j][i+1] [j] dp j i+1 i 1 MOD print(dp[-1][-1]) print dp[-1][-1] [-1] dp -1 -1 MOD = pow(10, 9) + 7 pow(10, 9) + 7 MOD tlist = list(map(int, input().split())) list(map(int, input().split())) tlist dp = [[1 for _ in range(n+1)] for _ in range(m+1)] [[1 for _ in range(n+1)] for _ in range(m+1)] dp m = map(int, input().split()) map(int, input().split()) m n, m = map(int, input().split()) map(int, input().split()) n slist = list(map(int, input().split())) list(map(int, input().split())) slist
MOD = pow(10, 9) + 7

n, m = map(int, input().split())
slist = list(map(int, input().split()))
tlist = list(map(int, input().split()))

dp = [[1 for _ in range(n+1)] for _ in range(m+1)]
for i, s in enumerate(slist):
  for j, t in enumerate(tlist):
    if s != t:
      dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD
    else:
      #if slist[i] == t and tlist[j] == s:
        dp[j+1][i+1] = (dp[j+1][i] + dp[j][i+1]) % MOD
      #else:
      #  dp[j+1][i+1] = ((dp[j+1][i] + dp[j][i+1]) % MOD - dp[j][i]) % MOD

print(dp[-1][-1])
