#1行目 width = int(input()) #2行目 blocknum = int(input()) #3行目 blocksize = input() split_blocksize=blocksize.split() blocksize_list = sorted(split_blocksize) sum_blocksize = 0 inblock = 0 for n in range(blocknum - 1): sum_blocksize += int(blocksize_list[n]) if sum_blocksize <= width: inblock += 1 else: break print(inblock)