#include<stdio.h>
#include<string.h>
#include<stdlib.h>

#define MAX_SIZE 100

int stack[MAX_SIZE];
int top = -1;

void push(int x)
{
    if(top>=MAX_SIZE-1)
    {
        
    }
    else
    {
        top++;
        stack[top] = x;
    }
}

int pop()
{
    if(top==-1)
    {
        printf("Stack underflow\n");
        return -1;
    }
    else
    {
        int item = stack[top];
        top--;
        return item;
    }
}
void peek()
{
    if(top==-1)
    {
        printf("Stack underflow\n");
    }
    else
    {
        printf("%d\n",stack[i]);
    }
}

void display()
{
    if(top==-1)
    {
        for(int i=0;i<=top;i++)
        {
            printf("%d",stack[i]);
        }
        printf("\n");
    }
}

int main()
{
    int q;
    scanf("%d",&q);
    
    if(q<0)
    {
        printf("Invalid input\n");
        return 0;
    }
    char command[10];
    int value;
    
    for(int i=0;i<q;i++)
    {
        scanf("%s",&command);
        
        if(strcmp(command,"PUSH")==0)
        {
            scanf("%d",&value);
            push(value);
        }
        else if(strcmp(command,"POP")==0)
        {
            pop();
        }
        else if(strcmp(command,"PEEK")==0)
        {
            peek();
        }
        else if(strcmp(command,"DISPLAY")==0)
        {
            display();
        }
    }
return 0;
}