import Data.Bool

solve :: Int -> Int -> [Int] -> Int
solve n k a = go 0 40 where
  go c (-1) = c
  go c e
    | cnt (c+2^e) >= k = go (c+2^e) (e-1)
    | otherwise = go c (e-1)
  cnt m = go 0 a a where
    go s xs ys
      | null ys || s+y >= m =
        length ys + bool (go (s-x) xr ys) 0 (null xs)
      | otherwise = go (s+y) xs yr
      where
        (x:xr) = xs
        (y:yr) = ys

main = do
  [n,k] <- readWords
  a <- readWords
  print $ solve n k a

readWords = map read . words <$> getLine