L = int(input()) N = int(input()) Ws = list(map(int,input().split())) counter = 0 Width = 0 Ws.sort() for i in range(0,N): if Width + Ws[i] <= L: Width += Ws[i] counter += 1 else: print(counter) break