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