L = gets.to_i N = gets.to_i ws = gets.split.map(&:to_i).sort len = 0 cnt = 0 while len < L len += ws.shift cnt += 1 end puts cnt.pred