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