#include <iostream>
using namespace std;
const int N = 1e5+10;
// 手动模拟一个栈,[1, tt] 是栈内元素,初始时 tt = 0,区间 [1, 0] 为空
int stk[N], tt;
int main() {
int n;
cin >> n;
for(int i=0;i<n;i++) {
int x;
cin >> x;
// 栈不空,且栈顶元素比当前元素大就弹出
while(tt && stk[tt] >=x) tt--;
// 出栈操作完毕后,栈顶元素就是左边第一个比当前元素小的
if(tt) cout << stk[tt] << ' ';
// 如果全部出栈了,那么左边就没有比当前元素小的,输出 -1
else cout << -1 << ' ';
// 最后将当前元素压入栈中
stk[++tt] = x;
}
return 0;
}