#include <bits/stdc++.h>

using namespace std;

const int N = 110;
int w[N], l[N], r[N], idx=1, root;

void insert(int &u, int x){
	if (!u) {
		u = ++idx;
		w[u] = x;
	}
	else if (x < w[u]) {
		if (l[u] == 0){
			cout << w[u] << endl;
		}
		insert(l[u], x);

	}
	
	else if (x > w[u]){
		if (r[u] == 0){
			cout << w[u] << endl;
		}
		insert(r[u], x);

	}
}
int main(){
	int n;
	
	while (cin >> n){
		idx = 1;
		for (int i=0; i<n; i++){
			w[i] = l[i] = r[i] = root = 0;
			
		}
		
		for (int i=0; i<n; i++){
			int x;
			cin >> x;
			if (i == 0){
				cout << -1 << endl;
			}
			insert(root, x);
		}
		

	}	
	
	return 0;
}