#include <iostream>
using namespace std;

struct BTree
{
    int val;
    struct BTree* lchild,*rchild;
    BTree(int x):val(x),lchild(nullptr),rchild(nullptr){}
};

void Insert(BTree*&root,int n,int pre)
{
    if(root==nullptr)
    {
        root=new BTree(n);
        cout<<pre<<endl;
    }
    else if(root->val<n)Insert(root->rchild, n, root->val);
    else if(root->val>n)Insert(root->lchild, n, root->val);

}

int main() {
    BTree*T=nullptr;
    int n;
    cin>>n;
    while(cin>>n)
    {
        Insert(T,n,-1);
    }
    return 0;
}
// 64 位输出请用 printf("%lld")