#include "bits/stdc++.h" using namespace std; using ll = long long; void Main() { int L, N; cin >> L >> N; vector W(N, 0); for (int i = 0; i < N; ++i) { cin >> W[i]; } sort(W.begin(), W.end()); int ans = 0; for (int i = 0; i < N; ++i) { if (L - W[i] >= 0) { ++ans; L -= W[i]; } } cout << ans << endl; } int main() { std::cout << std::fixed << std::setprecision(15); Main(); return 0; }