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