m = gets.to_i c = gets.to_i a = gets.split().map(&:to_i) a.sort! s = 0 r = 0 a.each_with_index do |c,i| if s + c <= m s += c r += 1 end end print r