#include <iostream>
using namespace std;

const short int link_array_size = 30; //количество элементов в одном звене

struct link //звено списка
{
	int array [link_array_size]; //массив, элементы которого и являются элементами стека
	short int capacity; //свободное место в массиве
	link* next; //адресс следующего звена
	link () //создание звена
	{
		capacity = link_array_size;
	}
	void link_push (int n)
	{
		capacity--;
		array [capacity] = n; 
	}
	int link_pop ()
	{
		capacity++;
		return array[capacity-1]; 
	}
};

struct stack //сам стек
{
	link* head; //указатель на первое звено 
	int s; //количество элементов в стеке
	stack (link* h = NULL) // создание стека
	{
		head = h;
		s = 0;
	}
	void add_link() //добавление звена
	{
		link* a = new link;
		a->next = head;
		head = a;
	}
	void destroy_link() //удаление звена 
	{
		link * a = head;
		head = a->next;
		delete a;
	}
	void push (int n)
	{
		if ((head == NULL)||(head->capacity == 0))
		{
			add_link();
		}
		head->link_push(n);
		s++;
	}
	int pop ()
	{
		if (s>0)
		{
			int n = (head->link_pop());
			if (head->capacity == link_array_size)
			{
			destroy_link();
			}
			s--;
			return n;
		}
		else
		{
			throw 0;
		}
	}
	int back()
	{
		if (s>0)
		{
			return head->array[head->capacity];
		}
		else
		{
			throw 0;
		}
	}
	int size()
	{
		return s;
	}
	void clear()
	{
		while (head!=NULL)
		{
			destroy_link();
		}
		s = 0;
	}
};

int main()
{
	string s;
	stack Q;
	while (cin>>s)
	{
		if (s == "push")
		{
			int n;
			cin>>n;
			Q.push(n);
			cout<<"ok"<<endl;
		}
		if (s == "pop")
		{
			try
			{
				cout<<Q.pop()<<endl;
			}
			catch (int e)
			{
				cout<<"error"<<endl;
			}
		}
		if (s == "back")
		{
			try
			{
				cout<<Q.back()<<endl;
			}
			catch (int e)
			{
				cout<<"error"<<endl;
			}
		}
		if (s == "size")
		{
			cout<<Q.size()<<endl;
		}
		if (s == "clear")
		{
			Q.clear();
			cout<<"ok"<<endl;
		}
		if (s == "exit")
		{
			cout<<"bye"<<endl;
			break;
		}
	}
	return 0;
}