i = input t = int b = t(i()) n = t(i()) l = [t(x) for x in i().split()] l.sort() s = 0 a = 0 for j in l: s += j if s <= b: a += 1 print(a)