#include<iostream>
#include<cstdio>
  
using namespace std;

struct TreeNode{
    int data;
    TreeNode* lchild;
    TreeNode* rchild;
    TreeNode(int c): data(c),lchild(NULL),rchild(NULL){}
};

TreeNode* Insert(TreeNode* root,int c,int father){
    if(root==NULL){
        root=new TreeNode(c);
        printf("%d\n",father);        //每次插入节点后,该节点对应的父亲节点的关键字值
    }
    else if(c < root->data)
        root->lchild=Insert(root->lchild,c,root->data);
    else 
        root->rchild=Insert(root->rchild,c,root->data);
    return root;
}

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
        TreeNode* root=NULL;            //建立空树
        for(int i=0;i<n;i++){
            int c;
            scanf("%d",&c);
            root=Insert(root,c,-1);        //如果没有父亲节点,则输出-1
        }
    }
    return 0;
}