l = gets.to_i n = gets.to_i w = gets.split.take(n).map(&:to_i).sort ans = 0 n.times {|x| if w[x] > l break end l -= w[x] ans += 1 } puts ans