l = gets.to_i n = gets.to_i w = gets.split.map(&:to_i).sort sum = 0 w.each_with_index do |e, idx| next if (sum += e) <= l puts idx exit end puts n