#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define MAX 10
void process_stack(int n) {
// Your logic here
int stack[MAX];
int top = -1; // Initialize stack as empty
for (int i = 0; i < n; i++) {
char operation[10];
scanf("%s", operation);
if (strcmp(operation, "push") == 0) {
int x;
scanf("%d", &x);
if (top < MAX - 1) {
stack[++top] = x; // Push x onto the stack
} else {
printf("Stack Overflow\n");
}
} else if (strcmp(operation, "pop") == 0) {
if (top >= 0) {
printf("%d\n", stack[top--]); // Pop and print the top value
} else {
printf("Stack Underflow\n");
}
}
}
}
int main() {
int n;
scanf("%d", &n);
getchar(); // Consume newline after number
process_stack(n);
return 0;
}