container_size = int(input()) num_on_box = int(input()) wl = sorted(list(map(int, input().split()))) # each block's width current_width = 0 for i, w in enumerate(wl, start=0): if current_width + w > container_size: print(i) exit() else: current_width += w print(num_on_box)