mx = gets.to_i n = gets.to_i a = gets.split.map(&:to_i).sort cnt = 0 while mx >= 0 && a.size >= 1 v = a.shift if v <= mx cnt += 1 mx -= v else puts cnt exit end end puts cnt