box_width = int(input()) block_num = int(input()) block_width_list = [int(x) for x in input().split(' ')] cnt = 0 block_total_width = 0 for block_width in sorted(block_width_list): block_total_width += block_width if block_total_width > box_width: break else: cnt += 1 print(cnt)