L = int(input()); N = int(input()); b = 0; W = input().split(); W.sort(); for i in range(N): b = b + int(W[i]); if (b > L): print(i); break;