L=int(input()) N=int(input()) W=sorted(map(int,input().split())) ANS=0 S=0 for w in W: if S+w<=L: ANS+=1 S+=w print(ANS)