l = int(input()) n = int(input()) w = list(map(int, input().split())) w.sort() i = 0 while i < n and l - w[i] >= 0: l -= w[i] i += 1 print(i)