L = input() N = input() group = [] W = raw_input() for i in range(0,N): split_W =W.split() a = int(split_W[i]) group.append(a) group.sort() for i in range(0,N+1): g = group[0:i] if sum(g) > L: print len(g[0:i])-1 break