import Data.Array

data Int_inf = Fin Int | Inf | Ninf  deriving (Show,Eq)

instance Ord Int_inf where
  compare Inf (Fin _) = GT
  compare (Fin _) Inf = LT
  compare Ninf (Fin _)= LT
  compare (Fin _) Ninf= GT
  compare (Fin x) (Fin y) = compare x y
  compare Inf Ninf = LT
  compare Ninf Inf = GT
  compare Inf Inf = EQ
  compare Ninf Ninf = EQ

instance Num Int_inf where
  (+) Inf (Fin _) =Inf
  (+) (Fin _) Inf =Inf
  (+) (Fin x) (Fin y) = Fin (x+y)
  (+) Inf Inf = Inf
  (+) Ninf Ninf = Ninf
  (+) Inf Ninf = undefined
  (+) Ninf Inf = undefined
  (*) Inf (Fin x) = if x>0 then Inf else if x<0 then Inf else undefined
  abs Inf = Inf
  abs Ninf = Inf
  abs (Fin x) = Fin (abs x)
  fromInteger x = (Fin (fromInteger x))
  negate (Fin x) = Fin (negate x)
  negate Inf = Ninf
  negate Ninf = Inf
  signum (Fin x) = (Fin (signum x))
  signum Inf  = Fin 1
  signum Ninf = Fin (-1)

instance Real Int_inf where
  toRational (Fin x) =toRational x
  toRational Inf     = undefined
  toRational Ninf    = undefined
--ナイーブな再帰：面額リスト、使う番号、金額、その時の枚数（不能な時は無限）
naive_rec::Array Int Int -> Int -> Int -> Int_inf
naive_rec _     0 k = if k==0 then Fin 0 else Inf
naive_rec item  i k = minimum [ (naive_rec item (i-1) (k - (j*(item!i))))+(Fin j) | j <- [0..div k (item!i)]  ]

--再帰アレイリストによるメモ。
list_memo::Array Int Int -> Int -> Int -> [Array Int Int_inf]
list_memo item i k = (listArray (0,k) ((Fin 0):(replicate k Inf))):
                                    [listArray (0,k)
                                        [minimum
                                            [prev!(j-l*(item!i))+(Fin l)
                                            |l<-[0.. div j (item!i)]]
                                        |j<-[0..k]]
                                    | (prev,i) <-zip (list_memo item i k) [1..]]

--アイテムリスト：アイテムリストサイズ：目標金額：答え
solver::[Int]->Int->Int->Int
solver item_ls m k = let item = listArray (1,m) item_ls in
                     let Fin x = (last (list_memo item m k))!k in
                     x


main::IO()
main=do
  kmc<-getLine
  let k:m:[]=map read (words kmc)
  datc<-getLine
  let item_ls = map read (words datc)
  print (solver item_ls m k)
