L = int(input()) N = int(input()) W = list(map(int,input())) W.sort() cnt=0 for i in W: if L - i>0: cnt+=1 L-=i else: break print(cnt)