from itertools import accumulate def main(): L = int(input()) N = int(input()) W = list(map(int, input().split())) W.sort() for idx, sum_ in enumerate(accumulate(W)): if sum_ > L: print(idx) break else: print(N) if __name__ == "__main__": main()