#include #include #include using namespace std; int main(){ int L, N; cin >> L >> N; vector W(N); for (int i = 0; i < N; i++){ cin >> W[i]; } sort(W.begin(), W.end()); int SAM=0; int ans = 0; for (int i = 0; i < N; i++){ SAM += W[i]; if (SAM <= L) ans++; else break; } cout << ans << endl; }