//#include <stdio.h>
//
//void rec(int k){
// if(k<1){
// return ;
// }
// rec(k/2);
// printf("%d",k%2);
//}
//
//int main()
//{
// int n;
// scanf("%d",&n);
// if(n==0){
// printf("0");
// }
// else{
// rec(n);
// }
//}
//#include<stdio.h>
//
//int main() {
// int n, arr[100] = {0};
// int k=0;
//
// scanf("%d", &n);
//
// for(;;) {
// arr[k++] = n%2;
// n/=2;
// if(n==0) {
// break;
// }
// }
//
// for(--k; k>=0; k--) {
// printf("%d", arr[k]);
// }
//
//
//}
////////////////////////////////////////////
// Episode 2: Data Structure
// Stack, Queue, Graph, Gready, Sort, DFS, BFS
// Search, BS
// Stack
//
//#include<stdio.h>
//
//#define SIZE 5 // macro function
//
//int stack[SIZE] = {0};
//int top=0;
//
//void push(int k) {
// int i;
// printf("%d\n",top);
// if(top==SIZE) {
// printf("Stack is Full\n");
// return;
// }
// stack[top++] = k;
// printf("%d\n",top);
//
//
//
//// if(stack[SIZE-1]!=0){
//// printf("Input Error\n");
//// return ;
//// }
//// for(i=0;i<SIZE;i++){
//// if(stack[i]==0){
//// stack[i]=k;
//// break;
//// }
//// }
//}
//
//void pop(){
// if(top==0) {
// printf("Stack is Empty\n");
// return ;
// }
// printf("%d\n",top);
// top--;
// printf("Output Data is %d\n", stack[top]);
// stack[top] = 0;
// printf("%d\n",top);
//
//// int i;
//// if(stack[0]==0){
//// printf("Data Not Found\n");
//// return ;
//// }
//// for(i=SIZE-1;i>=0;i--){
//// if(stack[i]!=0){
//// printf("%d\n",stack[i]);
//// stack[i]=0;
//// break;
//// }
//// }
//}
//
//void view() {
// int i;
//
// for(i=SIZE-1; i>=0; i--) {
// printf("%d: %d\n", i, stack[i]);
// }
//}
//
//int main() {
// int n, k;
//
// for(;;) {
// printf("1. push, 2. pop, 3. view ::");
// scanf("%d", &n);
//
// switch(n) {
// case 1:
// printf("Input Data is : ");
// scanf("%d", &k);
// push(k);
// break;
// case 2:
// pop();
// break;
// case 3:
// view();
// break;
// default:
// printf("Input Error\n");
// }
// }
//
//}
//#include <stdio.h>
//
//#define SIZE 1000000
//
//int stack[SIZE] = {0};
//int top=0;
//
//void push(int k){
// stack[top++]=k;
//}
//
//void pop(){
// if(top==0){
// return ;
// }
// top--;
// stack[top]=0;
//}
//
//int main()
//{
// int n, i, j;
// scanf("%d", &n);
// for(i=0;i<n;i++){
// scanf("%d",&j);
// if(j==0){
// pop();
// }
// else{
// push(j);
// }
// }
// j=0;
// for(i=0;i<=top;i++){
// j=j+stack[i];
// }
// printf("%d",j);
//}
//#include <stdio.h>
//
//#define SIZE 300
//
//int stack[SIZE] = {};
//int top=0;
//
//void push(int k){
// if(k<10){
// stack[top++]=k;
// return ;
// }
// push(k/10);
// stack[top++]=k%10;
//}
//
//int main(){
// int n, i;
// scanf("%d",&n);
// push(n);
// for(i=top;i>=1;i--){
// printf("%d",stack[i-1]);
// }
//}
//#include<stdio.h>
//#include<string.h>
//
//int main() {
// char str[1000] = {0};
//
// gets(str);
//
// for(int i=6; i<=strlen(str)-3; i++) {
// printf("%c", str[i]);
// }
// // strstr: pop(), top(), size(), empty()
// if(strstr(str, "pop()")) {
// printf("Activated");
// }
//
// if(strstr(str, "push")) {
// // push( xxxx )
// // 6 strlen(str)-3: boundary
// }
//}
#include <stdio.h>
#define SIZE 300
int stack[SIZE] = {0};
int top=0;
int result[SIZE] = {0};
int top2=0;
void push(int k){
stack[top]=k;
top=top+1;
}
void pop(){
if(top==0){
return ;
}
top=top-1;
stack[top]==0;
}
void ttop(){
if(top==0){
printf("-1\n");
return ;
}
printf("%d\n",stack[top-1]);
// result[top2++] = stack[top-1];
}
void size(){
printf("%d\n",top);
// result[top2++] = top;
}
void empty(){
if(top<=0){
printf("true\n");
}
else{
printf("false\n");
}
}
int main(){
int n, i, j, l;
char str[10000]={0};
scanf("%d\n",&n);
for(i=0;i<n;i++){
j=0;
l=0;
gets(str);
if(strstr(str,"pop")){
pop();
}
if(strstr(str,"push")){
for(int i=6; i<=strlen(str)-3; i++) {
l = str[i]-'0';
j=j*10+l;
}
push(j);
}
if(strstr(str,"top")){
ttop();
}
if(strstr(str,"size")){
size();
}
if(strstr(str,"empty")){
empty();
}
}
}



