l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i) w.sort! n.times do |i| l -= w[i] if l < 0 puts i return end end puts n