#include<iostream>
using namespace std;
const int N = 100010;
int st[N];
int tt = -1;
int n, x;
int main() {
cin >> n;
while(n -- ) {
scanf("%d", &x);
//如果当前元素比栈顶元素小,则不断的出栈,直到可以让该元素入栈
while(tt != -1 && x <= st[tt]) tt -- ;
if (tt == -1) {
cout << -1 << " ";
}else cout << st[tt] << " ";
st[ ++ tt ] = x;
}
}