#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

struct Node {
    int data;
    struct Node *next;
};

struct Node *front = NULL, *rear = NULL;

void enqueue(int value) {
    struct Node newNode = (struct Node)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;
    if (rear == NULL) {
        front = rear = newNode;
    } else {
        rear->next = newNode;   // as given in note
        rear = newNode;
    }
}

int dequeue() {
    if (front == NULL) {
        printf("Invalid input\n");
        return -1;
    }
    struct Node *temp = front;
    int val = temp->data;
    front = front->next;
    if (front == NULL) rear = NULL;
    free(temp);
    return val;
}

int isNumber(char *s) {
    for (int i = 0; s[i]; i++) {
        if (!isdigit(s[i])) return 0;
    }
    return 1;
}

int main() {
    char input[500];
    fgets(input, sizeof(input), stdin);

    char *token = strtok(input, " \n");
    while (token != NULL) {
        if (strcmp(token, "out") == 0) {
            int dispatched = dequeue();
            if (dispatched != -1)
                printf("%d\n", dispatched);
            else
                return 0; // stop if invalid
        } else if (isNumber(token)) {
            int num = atoi(token);
            if (num < 10 || num > 99) {
                printf("Invalid input\n");
                return 0;
            }
            enqueue(num);
        } else {
            printf("Invalid input\n");
            return 0;
        }
        token = strtok(NULL, " \n");
    }
    return 0;
}