#include #include using namespace std; int main() { int L, N, W[10010]; cin >> L >> N; for (int i = 0; i < N; ++i) cin >> W[i]; sort(W, W + N); int S = 0, i = 0; while(i < N) { S += W[i]; if (S > L)break; ++i; } cout << i << endl; }