#include #include #include #include #include #include #include using namespace std; typedef long long LL; 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()); LL ans = 0; LL sum = 0; for(int i = 0; i < N; i++){ if(sum + w[i] > L) break; ans++; sum += w[i]; } cout << ans << endl; return 0; }