L=int(raw_input()) N=int(raw_input()) W=map(int,raw_input().split()) value = 0 W.sort() i=0 for i in W: if L - i >= 0: L = L - i value += 1 else: break print value