#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testCase;
int num;
string command;
cin >> testCase;
stack<int> s;
for (int i = 0; i < testCase; i++) {
cin >> command;
if (command == "push") {
cin >> num;
s.push(num);
}
else if (command == "pop") {
if (s.size()) {
cout << s.top() << "\n";
s.pop();
}
else
cout << -1 << "\n";
}
else if (command == "size")
cout << s.size() << "\n";
else if (command == "empty") {
if (s.empty())
cout << 1 << "\n";
else
cout << 0 << "\n";
}
else if (command == "top") {
if (!s.empty())
cout << s.top() << "\n";
else
cout << -1 << "\n";
}
}
}