import sys
input = sys.stdin.readline
MOD = 10**9+7

n, m = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
  for j in range(m+1):
    if i == 0 or j == 0:
      dp[i][j] = 1
    else:
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
      if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= MOD
ans = dp[n][m]
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline MOD = 10**9+7 MOD 10**9+7 10**9 10 9 7 n, m = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split m S = list(map(int, input().split())) S list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split T = list(map(int, input().split())) T list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split [0]*(m+1) for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [0]*(m+1) [0] 0 m+1 m 1 dp = [[0]*(m+1) for _ in range(n+1)] dp [[0]*(m+1) for _ in range(n+1)] for i in range(n+1):
  for j in range(m+1):
    if i == 0 or j == 0:
      dp[i][j] = 1
    else:
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
      if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= MOD i range(n+1) range n+1 n 1 for j in range(m+1):
    if i == 0 or j == 0:
      dp[i][j] = 1
    else:
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
      if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= MOD j range(m+1) range m+1 m 1 if i == 0 or j == 0:
      dp[i][j] = 1
    else:
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
      if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= MOD i == 0 or j == 0 i == 0 i 0 j == 0 j 0 dp[i][j] = 1 dp[i][j] [i] dp i j 1 dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] dp[i][j] [i] dp i j dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1] dp[i][j-1] + dp[i-1][j] dp[i][j-1] [i] dp i j-1 j 1 dp[i-1][j] [i-1] dp i-1 i 1 j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
       S[i-1] == T[j-1] S[i-1] S i-1 i 1 T[j-1] T j-1 j 1 dp[i][j] += dp[i-1][j-1] dp[i][j] [i] dp i j dp[i-1][j-1] [i-1] dp i-1 i 1 j-1 j 1 dp[i][j] %= MOD dp[i][j] [i] dp i j MOD ans = dp[n][m] ans dp[n][m] [n] dp n m print(ans) print ans m = map(int, input().split()) map(int, input().split()) m T = list(map(int, input().split())) list(map(int, input().split())) T input = sys.stdin.readline sys.stdin.readline input n, m = map(int, input().split()) map(int, input().split()) n MOD = 10**9+7 10**9+7 MOD ans = dp[n][m] dp[n][m] ans S = list(map(int, input().split())) list(map(int, input().split())) S dp = [[0]*(m+1) for _ in range(n+1)] [[0]*(m+1) for _ in range(n+1)] dp
import sys
input = sys.stdin.readline
MOD = 10**9+7

n, m = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
dp = [[0]*(m+1) for _ in range(n+1)]
for i in range(n+1):
  for j in range(m+1):
    if i == 0 or j == 0:
      dp[i][j] = 1
    else:
      dp[i][j] = dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]
      if S[i-1] == T[j-1]:
        dp[i][j] += dp[i-1][j-1]
      dp[i][j] %= MOD
ans = dp[n][m]
print(ans)