l = gets.to_i n = gets.to_i w = gets.split(' ').map(&:to_i).sort sum = 0 ans = 0 n.times{|i| sum += w[i] if sum > l break else ans += 1 end } p ans