l = int(input()) _ = int(input()) w = sorted(list(map(int, input().split(' ')))) c = 0 for i in range(len(w)): if sum(w[0:i+1]) <= l: c = len(w[0:i+1]) else: break print(c)