#include <stdio.h>
#include <string.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");
        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(auto(numstr));
        }
        else if (strcmp(command,"peak")==0) {
            peek();
        }
        else {
            printf("invalid input\n");
            return 0;
        }
    }
    return 0;
}