#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int>moNiStack;
	vector<string>result;
	for (int i = 0; i < n; i++)
	{
		string command;
		cin >> command;
		if (command == "push")
		{
			int x;
			cin >> x;
			moNiStack.push_back(x);
		}
		else if (command == "pop")
		{
			if (moNiStack.empty())
			{
				result.push_back("error");
			}
			else
			{
				result.push_back(to_string(moNiStack[moNiStack.size() - 1]));
				moNiStack.pop_back();
			}
		}
		else if (command == "top")
		{
			if (moNiStack.empty())
			{
				result.push_back("error");
			}
			else
			{
				result.push_back(to_string(moNiStack[moNiStack.size() - 1]));
			}
		}
		else
		{
			;
		}
	}

	for (int i = 0; i < result.size(); i++)
	{
		cout << result[i] << endl;
	}
	return 0;
}