#include <iostream>
using namespace std;
const int N = 100010;
int stk[N], tt;
int main()
{
int n;
cin >> n;
while (n -- )
{
int x;
scanf("%d", &x); // 数据量大,用scanf速度快
while (tt && stk[tt] >= x) tt -- ; // 栈不为空并且栈顶元素大于x,弹出栈顶元素
if (tt) printf("%d ", stk[tt]); // 如果栈不为空,栈顶是其左边最小的数,输出栈顶元素
else printf("-1 "); //栈是空的,没有比x小的数,则返回-1
stk[ ++ tt] = x; // 把x插到栈里面
}
return 0;
}