#include using namespace std; #define int long long //typedef pair P; #define mod 1000000007 #define INF (1LL<<60) #define rep(i,n) for(int i=0, i##_len=(n); i istream& operator>>(istream& is, vector& vec) { for (T& x : vec) is >> x; return is; } // pair template ostream& operator<<(ostream& os, pair& pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template ostream& operator<<(ostream& os, const vector& vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); } os << "}"; return os; } // map template ostream& operator<<(ostream& os, map& map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "}"; return os; } // set template ostream& operator<<(ostream& os, set& set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; } os << "}"; return os; } #define DUMPOUT cerr void dump_func() { DUMPOUT << endl; } template void dump_func(Head&& head, Tail&& ... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); } #ifdef DEBUG #define DEB #define dump(...) \ DUMPOUT << " " << string(#__VA_ARGS__) << ": " \ << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" \ << endl \ << " ", \ dump_func(__VA_ARGS__) #else #define DEB if (false) #define dump(...) #endif #endif signed main() { int L,N; cin >> L >> N; vector W(N); rep(i,N) cin >> W[i]; sort(W.begin(), W.end()); int t = 0, ans=0; rep(i,N){ if(t+W[i]>L){ans=i; break;} t+=W[i]; } if(t<=L) ans=N; cout << ans << endl; return 0; }