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