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