L=int(input()) N=int(input()) W=list(map(int,input().split())) W_s=sorted(W) Wsum=0 for i in range(N): Wsum+=W_s[i] if Wsum>L: print(i) break if Wsum<=L: print(N)