#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5 + 10;
int stk[N], top = 0;
int main()
{
int n;
cin >> n;
while(n --)
{
int x;
cin >> x;
// 小于栈顶,直接出栈
while(x <= stk[top]){
top --;
}
// 栈空,直接入栈,返回-1
if(top == 0){
stk[++ top] = x;
cout << -1 << " ";
}
else if (x > stk[top]) // >=栈顶,入栈
{
stk[++ top] = x;
cout << stk[top - 1] << " ";
}
}
return 0;
}