#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
stack<int>sk;
while(n--)
{
string s;
int a;
cin>>s;
if(s=="push")
{
cin>>a;
sk.push(a);
}
else
{
if(!sk.empty())
{
if(s=="pop")
{
cout<<sk.top()<<endl;
sk.pop();
}
if(s=="top") cout<<sk.top()<<endl;
}
else cout<<"error"<<endl;
}
}
return 0;
}