import algorithm, sequtils, strutils
 
var
  l, n = parseInt readLine stdin
  ws = stdin.readLine.split.map parseInt
 
ws.sort cmp
 
var cnt = 0
 
for i in 0 ..< n:
  l -= ws[i]
  if l < 0:
    break
  inc cnt
 
echo cnt