L = int(input()) N = int(input()) W = sorted(map(int,input().split())) t = 0 s = 0 for i in W: s += i if s > L: print(t) break t += 1 else: print(t)