#include<iostream>
using namespace std;
const int N = 100010;
int n;
int st[N], top = -1;
/*
要取左边第一个小于x的数,判断栈顶元素>x则出栈即可。
别忘了将当前x入栈
*/
int main()
{
cin >> n;
for(int i = 0; i < n; i ++ )
{
int x;
scanf("%d", &x);
while(top > -1 && st[top] >= x)
top -- ;
if(top == -1)
printf("-1 ");
else
printf("%d ", st[top]);
st[++top] = x;
}
return 0;
}