#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

#define MAX_ACTIVITY 50
#define MIN_LABEL 10
#define MAX_LABEL 99

typedef struct Node {
    int label;
    struct Node *next;
} Node;

int main() {
    char input;
    fgets(input, sizeof(input), stdin);

    char *token = strtok(input, " \n");
    Node *front = NULL;
    Node *rear = NULL;
    int queue_size = 0;
    int dispatched[MAX_ACTIVITY];
    int dispatched_count = 0;
    int invalid = 0;

    while (token) {
        if (strcmp(token, "out") == 0) {
            if (queue_size == 0) {
                invalid = 1;
                break;
            }
            // Dispatch front node
            dispatched[dispatched_count++] = front->label;
            Node *temp = front;
            front = front->next;
            free(temp);
            if (front == NULL) rear = NULL;
            queue_size--;
        } else {
            // Validate label (integer between 10 and 99)
            int label = atoi(token);
            int valid = 1;
            for (int i = 0; token[i]; i++) {
                if (!isdigit(token[i])) valid = 0;
            }
            if (!valid || label < MIN_LABEL || label > MAX_LABEL) {
                invalid = 1;
                break;
            }
            Node *newNode = (Node *)malloc(sizeof(Node));
            newNode->label = label;
            newNode->next = NULL;
            if (rear) {
                rear->next = newNode; // Required usage
                rear = newNode;
            } else {
                front = rear = newNode;
            }
            queue_size++;
        }
        token = strtok(NULL, " \n");
    }

    if (invalid) {
        printf("Invalid input\n");
    } else {
        for (int i = 0; i < dispatched_count; i++) {
            printf("%d\n", dispatched[i]);
        }
    }

    // Free remaining nodes
    while(front){
        Node *temp = front;
        front = front->next;
        free(temp);
    }
    return 0;
}