L = int(input()) N = int(input()) W = input().split() W = list(map(int,W)) W = sorted(W) boxes = 0 length = 0 for i in W: if (length + i) <= L: length += i boxes += 1 else: print(boxes) break