#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define MAX_SIZE 5
int stack[MAX_SIZE];
int top=-1;
void push(int x)
{
    if(top==MAX_SIZE-1)
    {
        printf("Stack overflow\n");
        return;
    }
    stack[++top]=x;
}
void peek()
{
    if(top==-1)
    {
        printf("stack is empty\n");
    }
    else
    {
        printf("%d\n",stack[top]);
    }
}
int isIneger(char*s)
{
    if(*s=='\0')
    return 0;
    if(*s=='\0')
    s++;
    if(*s=='\0')
    return 0;
    while(*s)
    {
        if(!isdigit(*s))
        return 0;
        s++;
    }
    return 1;
}
int main()
{
    int n;
    if(scanf("%d",&n)!=1 || n<1 || n>1000)
    {
        printf("Invalid input");
        return 0;
    }
    char command[20],arg[20];
    for(int i=0;i<n;i++)
{
    if(scanf("%s",command)!=1)
    {
        printf("Invalid input");
        return 0;
    }
    if(strcmp(command,"push")==0)
    {
        if(scanf("%s",arg)!=1 || !isInteger(arg))
        {
            printf("Invalid input");
            return 0;
        }
        int value=atoi(arg);
        push(value);
    }
    else if(strcmp(command,"peek")==0)
    {
        peek();
    }
    else
    {
        printf("Invallid input\n");
        return 0;
    }
}
return 0;
}