#include <stdio.h>
#include <stdlib.h>
typedef struct tnode {
    int x;
    struct tnode* lchild;
    struct tnode* rchild;
} node, *pnode;
void creat_find(int n) {
    pnode r;
    pnode root = malloc(sizeof(node));
    r = root;
    scanf("%d", &root->x);
    root->lchild = NULL;
    root->rchild = NULL;
    printf("-1\n");
    while (n > 1) {
        pnode a = malloc(sizeof(node));
        scanf("%d", &a->x);
        a->lchild = NULL;
        a->rchild = NULL;

        while (1) {
            if (a->x > r->x) {
                if (r->rchild == NULL) {
                    printf("%d\n", r->x);
                    r->rchild = a;
                    r = root;
                    break;
                } else
                    r = r->rchild;
            } else {
                if (r->lchild == NULL) {
                    printf("%d\n", r->x);
                    r->lchild = a;
                    r = root;
                    break;
                } else
                    r = r->lchild;
            }
        }
        n--;
    }

}
int main() {
    int n;
    scanf("%d", &n);
    creat_find(n);
    return 0;

}