#include<stdio.h>
int queue[201] = {};
int rear = 0, front = 0;
void push(int data)
{
/// 정렬
rear ++;
queue[rear] = data;
//printf("%d %d\n",front, rear);
for (int i = 1 ; i < rear-front ; i ++)
{
for (int j = front + 1 ; j <= rear - i ; j ++)
{
//printf("\n\n%d %d\n\n", queue[j], queue[j + 1]);
if (queue[j] > queue[j + 1])
{
int k = queue[j];
queue[j] = queue[j + 1];
queue[j + 1] = k;
}
}
}
}
void top()
{
if (queue[rear] != 0)
{
printf("%d\n", queue[rear]);
}
else
{
printf("-1\n");
}
}
void pop()
{
if (rear != front)
{
front ++;
queue[front] = 0;
}
}
void size()
{
printf("%d\n", rear - front);
}
void empty()
{
if (rear == front)
{
printf("true\n");
}
else
{
printf("false\n");
}
}
int main()
{
int i, j, k, n, m;
char str[101] = {};
scanf("%d ", &n);
for (i = 1 ; i <= n ; i ++)
{
gets(str);
if (str[1] == 'u')
{
int sum = 0;
for (int q = 6 ; str[q] != ' ' ; q ++)
{
sum = sum * 10 + (str[q] - '0');
}
push(sum);
}
else if (str[0] == 't') top();
else if (str[0] == 'p') pop();
else if (str[0] == 's') size();
else if (str[0] == 'e') empty();
}
}