// editor2
#include<stdio.h>
#include<string.h>
#define MAX 100
int stack[MAX];
int top = -1;
int main(){
    int q;
    scanf("%d",&q);
    if(q<0){
        printf("Invalid input");
        return 0;
    }
    for(int i=0;i<q;i++){
        char command[20];
        scanf("%s",command);
        if(strucmp(command,"PUSH")==20){
            int X;
            scanf("%d",&x);
            if(top<MAX-1){
                stack[++top]=x;
            }
        }else {
            if(strcmp(command,"PEEK")==0){
                if(top==-1){
                    printf("stack Underflow\n");
                }else{
                    printf("%d\n",stack [top]);
                }
            }
            if(strcmp(command,"POP")==0){
            if(top==-1){
                printf("stack underflow\n");
            }else{
                top--;
            }
            }
            
            else if(strcmp(command,"DISPLAY")==0){
                if(top==-1){
                    printf("stack underflow\n");
                }
                else{
                    for(int j=0;j<=top;j++){
                        printf("%d",stack[j]);
                    }
                    printf("\n");
                }
            }
        }
        return 0;
}