L=int(input()) N=int(input()) W=[int(i) for i in input().split()] W.sort() max=0 j=0 while(1): max+=W[j] if max > L: break j += 1 print(j)