L = int(input()) N = input() width_list = input() sum = 0 count = 0 for num in sorted(width_list.split()): width = int(num) if sum + width > L: break else: sum += width count += 1 print(count)