#include <iostream>
using namespace std;

const int N = 1e5 + 10;

int q[N];
int n;
int top_index = -1;

int main() {
    cin >> n;
    while(n --)
    {
        string s;
        cin >> s;
        if(s == "push")
        {
            int x;
            cin >> x;
            q[++ top_index] = x;
        }
        if(s == "top")
        {
            if(top_index >= 0) cout << q[top_index] << endl;
            else cout << "error" << endl;
        }
        if(s == "pop")
        {
            if(top_index >= 0) cout << q[top_index --] << endl;
            else cout << "error" << endl;
        }
    }
}
// 64 位输出请用 printf("%lld")