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