L=int(input()) N=int(input()) W=[int(i) for i in input().split()] W.sort(reverse=True) S=0 i=0 for i in range(len(W)): S+=W[i] # print(S) i+=1 i=0 #print(L) while S > L: # print(S) S=S-W[i] # print(S) i+=1 #print(N) N-=i print(N)