# No.5 数字のブロック from bisect import bisect_left from itertools import accumulate def main(): L, N = tuple(map(int, [input().rstrip() for _ in range(2)])) A = sorted(map(int, input().rstrip().split())) ans = bisect_left(tuple(accumulate(A)), L) print(ans) if __name__ == "__main__": main()