#include #define rep(i,n) for(int i=0;i<(n);i++) #define ALL(A) A.begin(), A.end() using namespace std; typedef long long ll; typedef pair P; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int L; cin >> L; int N; cin >> N; vector w(N, 0); rep (i, N) cin >> w[i]; int sum = 0; int res = 0; sort(ALL(w)); rep (i, N){ if (sum + w[i] <= L){ sum += w[i]; ++res; } // edn if } // end rep cout << res << endl; return 0; }