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