#include <iostream>
using namespace std;
const int N = 1e5 + 5;
class stack{
private:
int s[N];
int top_index = 0;
public:
void push(int x){
s[top_index] = x;
top_index += 1;
}
void pop(){
if(top_index > 0){
top_index --;
cout << s[top_index] << endl;
}
else{
cout << "error" << endl;
}
}
void top(){
if(top_index > 0){
cout << s[top_index-1] << endl;
}
else{
cout << "error" << endl;
}
}
};
int main() {
stack s;
int n, x;
string op;
cin >> n;
for(int i = 0; i<n; i++){
cin >> op;
if(op=="push"){
cin >> x;
s.push(x);
}
else if(op=="pop"){
s.pop();
}
else if(op=="top"){
s.top();
}
}
return 0;
}
// 64 位输出请用 printf("%lld")