l, n, *w = map(int, open(0).read().split()) w.sort() s = 0 i = 0 while s <= l and i < n: s += w[i] i += 1 print(i - 1)