local bls, brs = bit.lshift, bit.rshift local limit = io.read("*n") local n = io.read("*n") local ret = 0 local t = {} for i = 1, n do t[i] = io.read("*n") end while true do ret = ret + 1 local tot = bls(1, n) local candpos, candval = -1, -1 for it = 0, tot - 1 do local a = 0 local tmp_it = it for i = 1, n do if tmp_it % 2 == 1 then a = a + t[i] end tmp_it = brs(tmp_it, 1) end if a <= limit then if candval < a then candpos, candval = it, a end end end local box = {} for i = 1, n do if candpos % 2 == 1 then box[i] = true end candpos = brs(candpos, 1) end for i = n, 1, -1 do if box[i] then table.remove(t, i) end end n = #t if #t == 0 then break end end print(ret)