#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_CAPACITY 5
typedef struct 
{
    int arr[MAX_CAPACITY];
    int top;
}Stack;
void initializeStack(Stack *s)
{
    s->top=-1;
}
void push(Stack *s,int value)
{
    if(s->top>=MAX_CAPACITY-1)
    {
        printf("Stack overflow\n");
    }
    else
    {
        s->arr[++(s->top)]=value;
    }
}
  void peek(Stack *s)
  {
      if(s->top==-1)
      {
          printf("Stack is empty\n");
      }
      else
      {
          printf("%d\n",s->arr[s->top]);
      }
  }
  int main()
  {
      Stack myStack;
      initializeStack(&myStack);
      int n;
      scanf("%d",&n);
      char command[10];
      int value;
      for(int i=0;i<n;i++)
      {
          scanf("%d",command);
          if(strcmp(command,"push")==0)
          {
              if(scanf("%d",&value)==1)
              {
                  push(&myStack,value);
              }
              else
              {
                  printf("Invalid input\n");
                  while(getchar()!='\n');
              }
              else if(strcmp(command,"peek")==0)
              {
                  peek(&myStack);
              }
              else
              {
                  printf("Invalid input\n");
                  while(getchar()!='\n');
              }
          }
          return 0;
      }
  }