def main l = gets.to_i n = gets.to_i ws = gets.split.map(&:to_i) cnt = 0 total = 0 ws.sort! while !ws.empty? cur = ws.shift break if l < total + cur cnt += 1 total += cur end cnt end puts main