// 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";

void push(int x)
{

if(top== MAX -1){
    printf("%s",STACK_EMPTY_MSG);
}
 
else{
    stack[++top]=x;
}
}
void peek(int x)
{
    {
if(top== -1){
    printf("%s",STACK_EMPTY_MSG);
}
else{
    printf("%d\n",stack[top]);
}
int is_valid_integer(const char*str){
    char* endptr;
    strtol(str, &endptr,10);
    return  *endptr=='\0';
    
    
}
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(strcmp (cmd,"push")==0){
        push(x);
    }
    else{
        printf("%s",invalid);
        
    
        
    while(getchar()!='\n');
    }
    else if(strcmp (cmd,"peek")==0){
        int x;
    scanf("%d",&x);
      peek();   
     }
}
    return 0;
}