#include<iostream>
using namespace std;
const int N=1e5+10;
int skt[N],tt;
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
while(tt&&skt[tt]>=x) tt--;
if(tt) cout<<skt[tt]<<" ";
else cout<<"-1"<<" ";
skt[++tt]=x;
}
return 0;
}