#include<iostream>
#include<stack>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
int N;
scanf("%d", &N);
cin.ignore();
stack<int> myStack;
for (int i = 0; i < N; i++)
{
string params;
getline(cin, params);
int blankIndex = params.find(" ");
string param1 = params.substr(0, blankIndex);
if (param1.compare("push") == 0)
{
int number = stoi(params.substr(blankIndex + 1, params.length()));
myStack.push(number);
}
else if (param1.compare("pop") == 0)
{
if (myStack.empty())
{
printf("-1\n");
}
else
{
int number = myStack.top();
printf("%d\n", number);
myStack.pop();
}
}
else if (param1.compare("size") == 0)
{
printf("%d\n", myStack.size());
}
else if (param1.compare("empty") == 0)
{
if(myStack.empty())
{
printf("1\n");
}
else
{
printf("0\n");
}
}
else if (param1.compare("top") == 0)
{
if (myStack.empty())
{
printf("-1\n");
}
else
{
printf("%d\n", myStack.top());
}
}
}
return 0;
}