// editor1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 5
int stack[MAX];
int top = - 1;
const char*STACK_OVERFLOW_MSG="Stack overflow\n";
const char*STACK_EMPTY_MSG="Stack is empty\n";
const char*invalid="Invalid Input\n";
int is_valid_integer(const char*str){
    char* endptr;
    strtol(str, &endptr,10);
    return  *endptr=='\0';
}
void push(int x)
{
if(top== MAX -1)
{
    printf("%s",STACK_EMPTY_MSG);
}
 else
 {
    stack[++top]=x;
}

void peek()
{
    {
if(top== -1){
    printf("%s",STACK_EMPTY_MSG);
}
else{
    printf("%d\n",stack[top]);
}

int main(){
 int n;
 scanf("%d",&n);
 for(int i=0;i<n;i++)
 {
    char cmd[10];
    scanf("%s",cmd);
    if(strcmp (cmd,"push")==0){
     int x;
       if(scanf ("%d",&x)==1) {
        push(x);   
       }
     else{
          printf("%s",invalid);
         while(getchar() != '\n');`
     }
    } else if(strcmp (cmd,"peek")==0){
      peek();  
    }
    while(getchar()!='\n');
 }
 return 0;
}