-- E - "Common Subsequence"
import Data.Array

main :: IO()
main = do
  [n, m] <- map read . words <$> getLine
  ns <- map read . words <$> getLine
  ms <- map read . words <$> getLine
  print $ solve n m ns ms

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve n m ns ms = (dp!(n, m) + 1) `mod` (10^9 + 7)
  where
    na = listArray (1, n) ns
    ma = listArray (1, m) ms
    dp = array ((0, 0), (n, m)) $ map (\p->(p, f p)) [(x, y)| x <- [0..n], y <- [0..m]]
    f (x, y)
      | x == 0 || y == 0 = 0
      | na!x == ma!y = (1 + dp!(x-1, y) + dp!(x, y-1)) `mod` (10^9 + 7)
      | otherwise = (dp!(x-1, y) + dp!(x, y-1) - dp!(x-1, y-1)) `mod` (10^9 + 7)