L = gets.to_i N = gets.to_i W = gets.split.take(N).map(&:to_i).sort sum = L p N.times{|i| sum -= W[i] break i if sum < 0 }