#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_SIZE 5

int stack[MAX_SIZE];
int top = -1;

// push function
void push(int x) {
    if (top == MAX_SIZE - 1){
    printf("Stack Overflow");
    return;
    }{
    stack[++top]=x;
    }
    
    void peek(){
    if(top==MAX_SIZE -1){
    printf("Stack is empty");
    }
    else
    {
    printf("%d",stack[top]);
    }
    }
    
    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;
}