// editor1
#include<stdio.h>
#include<string.h>
#define max 100
int stack[max];
int top=-1;

void push(int x,int n){
    if(top==max-1){
        printf("stack overflow");
        return ;
    }
    stack[++top]=x;
}
void pop(){
    if(top==-1){
        printf("stack is underflow");
        return ;
    }
    top--;
}
void peek(){
    if(top==-1){
        printf("stack is underflow");
        return ;
        
    }
    void display(){
        if (top ==-1){
            printf("stack is underflow");
            return ;
        }
        for(int i=0;i<=top;i++){
            printf("%d",stack[i]);
        }
        printf("\n");
    }
    
}
int main(){
    int n;
    char a[20];
    scanf("%d",&n);
    if(n<=0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%s",a);
        
        if(strcmp(a,"PUSH")==0)
        {
            int x;
            scanf("%d",&x);
            push(x,n);
        }
        else if(strcmp(a,"POP")==0){
            pop();
        }
        else if(strcmp(a,"PEEK")==0){
            peek();
        }
        else if(strcmp(a,"DISPLAY")==0){
            display();
        }
        else{
            printf("Invalid input");
        }
    }
    return 0;
}