// Online C++ compiler to run C++ program online
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int b, n, cb = 0;
cin >> b >> n;
vector<int> t;
vector<int> oper = {b};
for (int i = 0; i < n; i++) {
string op;
cin >> op;
if (op == "read") {
cout << oper[cb] << endl;
} else if (op == "credit" || op == "debit") {
int x;
cin >> x;
if (op == "credit") oper[cb] += x;
else oper[cb] -= x;
t.push_back(op == "credit" ? x : -x);
} else if (op == "rollback") {
int temp;
cin >> temp;
cb = temp - 1;
oper.resize(temp);
}
else if (op == "abort") {
int temp;
cin >> temp;
if (temp <= t.size()) {
oper[cb] -= t[temp - 1];
t[temp - 1] = 0;
}
}else if (op == "commit") {
oper.push_back(oper[cb]);
cb++;
}
}
return 0;
}
Ly8gT25saW5lIEMrKyBjb21waWxlciB0byBydW4gQysrIHByb2dyYW0gb25saW5lCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewogICAgaW50IGIsIG4sIGNiID0gMDsKICAgIGNpbiA+PiBiID4+IG47CiAgICB2ZWN0b3I8aW50PiB0OwogICAgdmVjdG9yPGludD4gb3BlciA9IHtifTsKCiAgICBmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykgewogICAgICAgIHN0cmluZyBvcDsKICAgICAgICBjaW4gPj4gb3A7CiAgICAgICAgaWYgKG9wID09ICJyZWFkIikgewogICAgICAgICAgICBjb3V0IDw8IG9wZXJbY2JdIDw8IGVuZGw7CiAgICAgICAgfSBlbHNlIGlmIChvcCA9PSAiY3JlZGl0IiB8fCBvcCA9PSAiZGViaXQiKSB7CiAgICAgICAgICAgIGludCB4OwogICAgICAgICAgICBjaW4gPj4geDsKICAgICAgICAgICAgaWYgKG9wID09ICJjcmVkaXQiKSBvcGVyW2NiXSArPSB4OwogICAgICAgICAgICBlbHNlIG9wZXJbY2JdIC09IHg7CiAgICAgICAgICAgIHQucHVzaF9iYWNrKG9wID09ICJjcmVkaXQiID8geCA6IC14KTsKICAgICAgICB9ICBlbHNlIGlmIChvcCA9PSAicm9sbGJhY2siKSB7CiAgICAgICAgICAgIGludCB0ZW1wOwogICAgICAgICAgICBjaW4gPj4gdGVtcDsKICAgICAgICAgICAgY2IgPSB0ZW1wIC0gMTsKICAgICAgICAgICAgb3Blci5yZXNpemUodGVtcCk7CiAgICAgICAgfQogICAgICAgIGVsc2UgaWYgKG9wID09ICJhYm9ydCIpIHsKICAgICAgICAgICAgaW50IHRlbXA7CiAgICAgICAgICAgIGNpbiA+PiB0ZW1wOwogICAgICAgICAgICBpZiAodGVtcCA8PSB0LnNpemUoKSkgewogICAgICAgICAgICAgICAgb3BlcltjYl0gLT0gdFt0ZW1wIC0gMV07CiAgICAgICAgICAgICAgICB0W3RlbXAgLSAxXSA9IDA7CiAgICAgICAgICAgIH0KICAgICAgICB9ZWxzZSBpZiAob3AgPT0gImNvbW1pdCIpIHsKICAgICAgICAgICAgb3Blci5wdXNoX2JhY2sob3BlcltjYl0pOwogICAgICAgICAgICBjYisrOwogICAgICAgIH0KICAgICAgICAKICAgIH0KICAgIHJldHVybiAwOwp9Cg==