#include #include #include using namespace std; int main() { int i; int L, N, SUM = 0; vector W; cin >> L; cin >> N; for ( i = 0; i < N; i++ ) { int Wi; cin >> Wi; W.push_back(Wi); } sort(W.begin(), W.end()); for( i = 0; i < N; i++ ){ SUM += W[i]; if ( SUM > L ) break; } if ( SUM <= L ) i = i - 1; cout << i << endl; return 0; }