-- E - "Common Subsequence"
import Data.Array
-- ------------------
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

-- ByteStringを用いた入力
readInt = fst . fromJust . BS.readInt

-- 整数を一つ受け取る
getInt = readInt <$> BS.getLine

-- 長さnの整数列を受け取る
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
-- ------------------

main :: IO()
main = do
  (n, m) <- (\v -> (v VU.! 0, v VU.! 1)) <$> getIntVec 2
  nv <- getIntVec n
  mv <- getIntVec m
  print $ solve n m nv mv

solve n m nv mv = (dp!(n, m) + 1) `mod` (10^9 + 7)
  where
    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
      | nv VU.! (x-1) == mv VU.! (y-1) = (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)