# 大きな箱の幅とブロックの数を入力 box_width = int(input()) num_of_blocks = int(input()) # 各ブロックの幅をリストに入れる width_of_blocks = list(map(int, input().split())) # クイックソートの導入 def quick_sort(lst): # クイックソート関数の定義 if len(lst) <= 1: return lst pivot = lst[0] left = [] center = [] right = [] for v in lst: if v < pivot: left.append(v) elif v > pivot: right.append(v) else: center.append(v) left = quick_sort(left) right = quick_sort(right) return left + center + right # ブロックを小さい順に並び替える sorted_blocks = quick_sort(width_of_blocks) sum_of_width = 0 count = 0 for i in sorted_blocks: sum_of_width += i count += 1 if sum_of_width > box_width: print(count - 1) break if i == sorted_blocks[num_of_blocks - 1]: print(count)