l = gets.to_i
n = gets.to_i
ws = gets.split.map(&:to_i).sort
ans = 0
ws.each do |w|
  if l >= w
    ans += 1
    l -= w
  end
end 
puts ans