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

MOD = 1000000007

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

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

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

    sum[i][j] %= MOD


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