#include using namespace std; #ifdef LOCAL #include "settings/debug.cpp" #define _GLIBCXX_DEBUG #else #define Debug(...) void(0) #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int l, n; cin >> l >> n; vector w(n); rep(i, n) cin >> w[i]; sort(w.begin(), w.end()); int ans = 0; rep(i, n) { if (l >= w[i]) { l -= w[i]; ans++; } } cout << ans << endl; return 0; }