#include <stdio.h>
#include <stdint.h>
#include <string.h>
#define MAX 10
int stack[MAX];
int top = -1;
void push(int x) {
if (top >= MAX - 1) {
printf("Stack Overflow\n");
} else {
stack[++top] = x;
}
}
void pop() {
if (top < 0) {
printf("Stack Underflow\n");
} else {
printf("%d\n", stack[top--]);
}
}
void process_stack(int n) {
char line[20];
for (int i = 0; i < n; i++) {
fgets(line, sizeof(line), stdin);
if (strncmp(line, "push", 4) == 0) {
int x;
sscanf(line + 5, "%d", &x); // Extract number after "push "
push(x);
} else if (strncmp(line, "pop", 3) == 0) {
pop();
}
}
}
int main() {
int n;
scanf("%d", &n);
getchar(); // Consume newline after number
process_stack(n);
return 0;
}