// editor1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_SIZE 5   // stack is fixed at 5

int stack[MAX_SIZE];
int top = -1;

// push function
void push(int x) {
    if (top == MAX_SIZE - 1) {
        printf("Stack overflow\n");
        return;
    }
    stack[++top] = x;
}

// peek function
void peek() {
    if (top == -1) {
        printf("Stack is empty\n");
    } else {
        printf("%d\n", stack[top]);
    }
}

// check if string is integer
int isInteger(char *s) {
    if (*s == '\0') return 0;
    if (*s == '-' || *s == '+') 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\n");
        return 0;
    }

    char command[20], arg[20];

    for (int i = 0; i < n; i++) {
        if (scanf("%s", command) != 1) {
            printf("Invalid input\n");
            return 0;
        }

        if (strcmp(command, "push") == 0) {
            if (scanf("%s", arg) != 1 || !isInteger(arg)) {
                printf("Invalid input\n");
                return 0;
            }
            int value = atoi(arg);
            push(value);
        }
        else if (strcmp(command, "peek") == 0) {
            peek();
        }
        else {
            printf("Invalid input\n");
            return 0;
        }
    }

return 0;