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