L=gets.chomp.to_i N=gets.chomp.to_i B=gets.chomp.split.map {|x| x.to_i} def numbers(l,n,b) total = 0 c = 0 b.sort! b.each do |x| if total + x > l break end total += x c += 1 end return c end puts numbers(L,N,B)