L=int(raw_input()) N=int(raw_input()) W=map(int,raw_input().split()) Wsort=sorted(W) Wsum=0 for i in xrange(N): Wsum+=W[i] if Wsum>L: print i break if L>=sum(W): print N