#include<iostream>
using namespace std;

typedef struct node{
	int val;
	struct node *left, *right;
}bittree, *tree;

//递归建树,并且返回父亲节点
int build(tree &t, tree node){
	if(t == NULL){
		t = node;
		return -1;
	}
	if(t->val > node->val){
		if(t->left == NULL){
			t->left = node;
			return t->val;
		}else{
			return build(t->left, node);
		}
	}else if(t->val < node->val){
		if(t->right == NULL){
			t->right = node;
			return t->val;
		}else{
			return build(t->right, node);
		}
	}else{
		return -1;
	}
}

int main(){
	int n, m;
	cin >> n;
	tree t = NULL;
	
	for(int i = 0; i < n; i++){
		cin >> m;
		tree node = (tree)malloc(sizeof(bittree));
		node->left = NULL;
		node->right = NULL;
		node->val = m;
		cout << build(t, node) << endl;
	}
	return 0;
}