l = int(input()) n = int(input()) w = list(map(int,input().split())) w.sort() c = 0 for i in w: if l < i: break l -= i c += 1 print(c)