#include #define INF 2000000000000000000 #define ll long long #define pll pair using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll L, N; cin >> L >> N; vector W(N); for (ll i = 0; i < N; ++i) { cin >> W.at(i); } sort(W.begin(), W.end()); ll sum = 0; for (ll i = 0; i < N; ++i) { sum += W.at(i); if (sum > L) { cout << i << "\n"; return 0; } } cout << N << "\n"; }