{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Int
solve !n !m !ws = (\(x, _, _) -> x) $ foldl'
  ( \(!p, !pp, wn) !n -> if not (null wn) && head wn == n
    then (0, p, tail wn)
    else ((p + pp) `mod` 1000000007, p, wn)
  )
  (1, 0, VU.toList ws)
  [1 .. n]

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an <-
    VU.replicateM m $ (\vec -> vec VU.! 0) . VU.unfoldrN 1 readInt <$> B.getLine
  print $ solve n m an
