l = gets.to_i n = gets.to_i ws = gets.split(" ").map(&:to_i).sort count = 0 while ws.size > 0 w = ws.shift break if l < w count += 1 l -= w end p count