#include #include #include #include #include #include using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; using P = pair; int main() { int L,N; cin >> L >> N; vector W(N); rep(i,N) { cin >> W[i]; } sort(W.begin(),W.end()); int sum = 0; int cnt = 0; rep(i,N) { sum += W[i]; if(sum>L) { sum -= W[i]; break; } else { cnt++; } } cout << cnt << endl; }