l = int(input()) n = int(input()) w = sorted([int(i) for i in input().split()]) for i in range(len(w)): if sum(w[:i+1]) > l or i == len(w): print(i) break elif sum(w[:i+1]) == l: print(i + 1) break