def max_blocks_in_box(L, widths): widths.sort() total_width = 0 count = 0 for w in widths: if total_width + w <= L: total_width += w count += 1 else: break return count L = int(input()) N = int(input()) widths = list(map(int, input().split())) result = max_blocks_in_box(L, widths) print(result)