i,ip = int,input l, n, bl, s, t = i(ip()), i(ip()), sorted(map(i,ip().split())), 0, 0 for j in bl: if s + j <= l: s += j t += 1 print(t)