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