include [HTML_REMOVED]
using namespace std;
const int N=100010;
int stk[N], hh;
int main() {
int m,x;
cin >>m;
while(m--){
cin>>x;
//注意这里是while一直找到不符合条件的hh再退出
while(hh && stk[hh]>=x) hh--;
if(hh){
cout<<stk[hh]<<" ";
}else {
cout<<-1<<" ";
}
stk[++hh]=x;
}
return 0;
}