#include <iostream>

using namespace std;

#define MaxSize 100000

class zhan{

private:

    int a[MaxSize];

    int t=0;

public:

    void push(int x){

        a[t]=x;

        t++;

    }

    void pop(){

        if(t>0){

            t--;

            cout<<a[t]<<endl;

        }

        else{

            cout<<"error"<<endl;

        }

    }

    void top(){

        if(t>0){

            cout<<a[t-1]<<endl;

        }

        else{

            cout<<"error"<<endl;

        }

    }

};

int main() {

    int n,x;

    string ch;

    zhan zh1;

    cin>>n;

    while(n--){

        cin>>ch;

        if(ch=="push"){

            cin>>x;

            zh1.push(x);

        }

        else if(ch=="pop"){

            zh1.pop();

        }

        else zh1.top();

    }

}