#include<iostream>
using namespace std;
const int N = 1e5 + 10;
int stk[N], tt;
int main()
{
    int n;
    cin >> n;
    for(int i = 1; i <= n; i ++)
    {
        int x;
        cin >>x;
                //栈顶就是左边第一个比它小的元素,
                while(tt && stk[tt] >= x)
        {
            tt --;
        }
        if(tt)cout << stk[tt]<<" ";
        else cout <<-1<<" ";
        stk[++ tt] = x;
    }
    return 0;
}