# coding:utf-8 import statistics hako_L = int(input()) block_num = int(input()) block_list = list(map(int, input().split())) block_list = sorted(block_list) list_center = statistics.median(block_list) a = 0 i = 0 c = 0 while True: try: c += 1 a += block_list[i] i += 1 if a > hako_L: break else: continue except IndexError: break print(c - 1)