wide = int(input()) kinds = int(input()) boxes = list(map(int, input().split())) boxes.sort() count = 0 for box in boxes: if wide >= box: wide = wide - box count += 1 else: break print(count)