MAX = int(input()) NUM = input() blocks = list(input().split()) #print("blocks", blocks) blocks_i = [int(s) for s in blocks] blocks_i.sort() #print("blocks_i", blocks_i) n = 0 while MAX > blocks_i[n]: MAX = MAX - blocks_i[n] # print(n+1, blocks_i[n],"MAX",MAX) n += 1 print(n)