#yukicoder No.5 数字のブロック L, N, *W = map(int, open(0).read().split()) W = sorted(W) total = 0 cnt = 0 for i in range(N): total += W[i] if total > L: break else: cnt += 1 print(cnt)