L = int(input()) N = int(input()) W = [int(i) for i in input().split()] W.sort() sum=0 j=0 for a in range(N): if sum+W[j] <=L: sum+=W[j] else: break j+=1 print(j)