L = int(input()) # L:箱の幅 N = int(input()) # N:ブロックの数 *W_list,=map(int,input().split()) W_list.sort() print(W_list) wsum = 0 count = 0 while wsum + W_list[0] <= L: wsum += W_list[0] del W_list[0] if W_list == []: count += 1 break count += 1 print(count)