L = int(input()) N = int(input()) blocks = list(map(int, input().split())) blocks = sorted(blocks) count = 0 while blocks: if L > 0: L = L - blocks[0] count = count + 1 blocks.pop(0) else: break if L < 0 : print(count - 1) else: print(count)