L = int(raw_input()) N = int(raw_input()) W = sorted(map(int, raw_input().split())) s = 0 for i in range(N + 1): s += W[i] if s > L: print i break