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