import sys readline = sys.stdin.readline read = sys.stdin.read w,_,*a = map(int,read().split()) a.sort() d = ans = 0 for i in a: if d+i < w: d += i ans += 1 print(ans)