L = int(input()) N = int(input()) w = list(map(int, input().split())) n = 0 s = int(0) w.sort() for x in range(len(w)): s += w[x] n += 1 if s > L: print(n-1) break if s <= L: print(n)