#include<bits/stdc++.h>

using namespace std;

const int N = 100003;
string a[N];
int b[N],c[N];

int main()
{
	int n,j=0,x=0,y=0;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		if(a[i] == "push")
		{
			cin >> b[i];
		}
	}
	
	for(int i=0;i<n;i++)
	{
		if(a[i] == "push")
		{
			c[j++] = b[i];
			x++;
		}
		else if(a[i] == "pop")
		{
			if(y<x)
				cout << c[y++] << endl;
			else
			  cout << "error" << endl;
		}
		else
		{
			if(y<x)
			  cout << c[y] << endl;
			else
			  cout << "error" << endl;
		}
	}
	return 0;
}