box = int(input()) num = int(input()) blocks = [int(i) for i in input().split(' ')] s_blocks = sorted(blocks) for i in range(num): box -= s_blocks.pop(0) if box < 0: print(i) break if box > 0: print(num)