L=int(input()) N=int(input()) W=list(map(int,input().split())) if sum(W)<=L: print(N) else: W.sort() X=0 k=0 while (X<=L) and (k