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