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