n, m = map(int, input().split()) 
s = list(map(int, input().split())) 
t = list(map(int, input().split())) 

MOD = 1000000007

dp= [[0] * m for _ in range(n)] 

for i, si in enumerate(s):  
  for j, tj in enumerate(t):
    if i > 0:
      dp[i][j] += dp[i-1][j]
      
    if j > 0:
      dp[i][j] += dp[i][j-1]

    if si == tj:
      dp[i][j] += 1
    elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
    dp[i][j] %= MOD

print((dp[n-1][m-1] + 1) % MOD) 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 MOD = 1000000007 MOD 1000000007 [0] * m for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) [0] * m [0] 0 m dp= [[0] * m for _ in range(n)] dp [[0] * m for _ in range(n)] for i, si in enumerate(s):  
  for j, tj in enumerate(t):
    if i > 0:
      dp[i][j] += dp[i-1][j]
      
    if j > 0:
      dp[i][j] += dp[i][j-1]

    if si == tj:
      dp[i][j] += 1
    elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
    dp[i][j] %= MOD i si enumerate(s) enumerate s for j, tj in enumerate(t):
    if i > 0:
      dp[i][j] += dp[i-1][j]
      
    if j > 0:
      dp[i][j] += dp[i][j-1]

    if si == tj:
      dp[i][j] += 1
    elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
    dp[i][j] %= MOD j tj enumerate(t) enumerate t if i > 0:
      dp[i][j] += dp[i-1][j]
      
     i > 0 i 0 dp[i][j] += dp[i-1][j] dp[i][j] [i] dp i j dp[i-1][j] [i-1] dp i-1 i 1 j if j > 0:
      dp[i][j] += dp[i][j-1]

     j > 0 j 0 dp[i][j] += dp[i][j-1] dp[i][j] [i] dp i j dp[i][j-1] [i] dp i j-1 j 1 if si == tj:
      dp[i][j] += 1
    elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
     si == tj si tj dp[i][j] += 1 dp[i][j] [i] dp i j 1 elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
     i > 0 and j > 0 i > 0 i 0 j > 0 j 0 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 print((dp[n-1][m-1] + 1) % MOD) print (dp[n-1][m-1] + 1) % MOD dp[n-1][m-1] + 1 dp[n-1][m-1] [n-1] dp n-1 n 1 m-1 m 1 1 MOD MOD = 1000000007 1000000007 MOD n, m = map(int, input().split()) map(int, input().split()) n m = map(int, input().split()) map(int, input().split()) m t = list(map(int, input().split())) list(map(int, input().split())) t dp= [[0] * m for _ in range(n)] [[0] * m for _ in range(n)] dp s = list(map(int, input().split())) list(map(int, input().split())) s
n, m = map(int, input().split()) 
s = list(map(int, input().split())) 
t = list(map(int, input().split())) 

MOD = 1000000007

dp= [[0] * m for _ in range(n)] 

for i, si in enumerate(s):  
  for j, tj in enumerate(t):
    if i > 0:
      dp[i][j] += dp[i-1][j]
      
    if j > 0:
      dp[i][j] += dp[i][j-1]

    if si == tj:
      dp[i][j] += 1
    elif i > 0 and j > 0:
      dp[i][j] -= dp[i-1][j-1]
    
    dp[i][j] %= MOD

print((dp[n-1][m-1] + 1) % MOD)