#include <iostream>
#include <queue>
#include <sstream>
#include <string>
using namespace std;

int main() {
    string line;
    getline(cin, line);

    queue<int> patients;
    stringstream ss(line);
    string token;

    while (ss >> token) {
        if (token == "B") {
            if (!patients.empty()) {
                cout << patients.front() << " ";
                patients.pop();
            } else {
                cout << "Invalid input" << endl;
                return 0; // End program if bell rings with no patients
            }
        } else {
            // Convert slip number to integer and add to queue
            patients.push(stoi(token));
        }
    }
    return 0;
}