#include using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int n, q; cin >> n >> q; map rate; set> st_fixed, st_not_fixed; for (; q--;) { int type; cin >> type; if (type == 1) { string s; int r; cin >> s >> r; rate[s] = r; st_not_fixed.insert({r, s}); if (st_fixed.size() + st_not_fixed.size() > n) { auto it = st_not_fixed.begin(); cout << it->second << "\n"; st_not_fixed.erase(it); } } else if (type == 2) { int x; cin >> x; n -= x; while (st_fixed.size() + st_not_fixed.size() > n) { if (!st_not_fixed.empty()) { auto it = st_not_fixed.begin(); cout << it->second << "\n"; st_not_fixed.erase(it); } else { auto it = st_fixed.begin(); cout << it->second << "\n"; st_fixed.erase(it); } } } else { string s; int x; cin >> s >> x; n += x; if (st_not_fixed.count({rate[s], s})) { st_fixed.insert({rate[s], s}); st_not_fixed.erase({rate[s], s}); } } } }