boxLength = int(input()) blockNum = int(input()) blockWidths = input() max = 0 blockWidths = list(map(int, blockWidths.split())) blockWidths.sort() for width in blockWidths: boxLength -= width if boxLength >= 0: max += 1 else: break print(max)