l = gets.chomp.to_i n = gets.chomp.to_i ary = [] ary1 = [] a = 0 b = 0 ary = gets.chomp.split ary.each do |i| ary1 << i.to_i end ary1.sort.each do |i| if a < l a += i b += 1 end end puts b - 1