{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import Data.Foldable
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 Int32 -> Int32
solve !n !k !an = VU.last $ V.last dp
 where
  big = 10 ^ 9 + 7

  mod1 x y | x >= y    = x - y
           | otherwise = x

  dp :: V.Vector (VU.Vector Int32)
  dp = V.postscanl'
    (\(!dpi) (!i) -> VU.scanl'
      (\(!dpij) (!j) ->
        let !p = if j - fromIntegral (an VU.! i) - 1 >= 0
              then dpi VU.! (j - fromIntegral (an VU.! i) - 1)
              else 0
            !q = dpi VU.! j
            !a = dpij `mod1` big + (q - p) `mod1` big
        in  a `mod1` big
      )
      1
      (VU.generate k (+ 1))
    )
    (VU.generate (k + 1) (\i -> if i == 0 then 1 else 0))
    (V.convert $ VU.generate n id)

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

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