l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort sum = count = 0 w.each_with_index do |e, idx| if (sum += e) > l puts idx exit end end puts n