#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int st[N];
int n, x, top = -1;
string s;
int main()
{
    cin>>n;
    while (n--) {
        cin>>s;
        if (s == "push") {
            cin>>x;
            st[++top] = x;
        }else if (s == "top") {
            if (top == -1) {
                cout<<"error"<<endl;
            } else {
                cout<<st[top]<<endl;
            }
        }else if (s == "pop") {
            if (top == -1) {
                cout<<"error"<<endl;
            } else {
                cout<<st[top]<<endl;
                --top;
            }
        }
    }
    
    return 0;
}