box_size = int(input()) block_num = int(input()) blocks = list(map(int, input().split())) blocks.sort() # print(box_size) # print(block_num) # print(blocks) answer = 0 for block in blocks: box_size = box_size - block if box_size >= 0: answer += 1 else: break print(answer)