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