#include <iostream>
using namespace std;

typedef struct Node {
    int data;
    Node* lchild, *rchild;
} Node;

void create(Node* &n, int data = -1) {
    n = new Node;
    n->data = data;
    n->lchild = n->rchild = NULL;
}

void insert(Node* head, int data) {
    if (head->data < 0) {
        cout << head->data << endl;
        head->data = data;
        return;
    }
    if (data < head->data) {
        if (head->lchild == NULL) {
            cout << head->data << endl;
            Node* Temp;
            create(Temp, data);
            head->lchild = Temp;
        } else {
            insert(head->lchild, data);
        }
    } else {
        if (head->rchild == NULL) {
            cout << head->data << endl;
            Node* Temp;
            create(Temp, data);
            head->rchild = Temp;
        } else {
            insert(head->rchild, data);
        }
    }
}

int main() {
    int n, data;
    Node* head;
    create(head);
    while (cin >> n) {
        while(n-- > 0){
            cin >> data;
            insert(head, data);
        }
    }
    return 0;
}