import math L = int(input()) N = int(input()) W = input().split(" ") W = [int(c) for c in W] W.sort() s = 0 ans = 0 for i in W: if s+i > L: break else: s+=i ans+=1 print(ans)