#include using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) void solve() { ll n, q; cin >> n >> q; set> que; map rs; rep(qi, q) { ll t; cin >> t; if (t == 1) { string s; ll r; cin >> s >> r; que.emplace(1, -r, s); rs[s] = r; } else if (t == 2) { ll x; cin >> x; n -= x; } else if (t == 3) { string s; ll x; cin >> s >> x; n += x; ll r = rs[s]; que.erase({1, -r, s}); que.emplace(0, -r, s); } while (ll(que.size()) > n) { auto [i, r, s] = *que.rbegin(); cout << s << '\n'; que.erase({i, r, s}); } } } int main() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); int T = 1; for (int t = 0; t < T; t++) { solve(); } return 0; }