#include using namespace std; int main() { int n, q; cin >> n >> q; int pc = n; map rate; map name; set fixed; set stay; vector left; for (int i = 0; i < q; i++) { int op; cin >> op; if (op == 1) { string s; cin >> s; int r; cin >> r; stay.insert(r); name[r] = s; rate[s] = r; // not saver set tmp; for (auto e : stay) { if (stay.size() - tmp.size() <= pc) { break; } if (fixed.count(e)) continue; tmp.insert(e); } // saver for (auto e : stay) { if (stay.size() - tmp.size() <= pc) { break; } if (not fixed.count(e)) continue; tmp.insert(e); } for (auto e : tmp) stay.erase(e), left.push_back(name[e]); } else if (op == 2) { int x; cin >> x; pc -= x; // not saver set tmp; for (auto e : stay) { if (stay.size() - tmp.size() <= pc) { break; } if (fixed.count(e)) continue; tmp.insert(e); } // saver for (auto e : stay) { if (stay.size() - tmp.size() <= pc) { break; } if (not fixed.count(e)) continue; tmp.insert(e); } for (auto e : tmp) stay.erase(e), left.push_back(name[e]); } else { string s; cin >> s; int r = rate[s]; fixed.insert(r); int x; cin >> x; pc += x; } } for (auto e : left) { cout << e << endl; } }