#include <bits/stdc++.h>
using namespace std;
const int N=1e5+1e4;
int s[N],tt;
int n;
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
int x;
cin>>x;
while(tt&&s[tt]>=x)tt--;
if(tt)cout<<s[tt]<<" ";
else cout<<"-1"<<" ";
s[++tt]=x;
}
return 0;
}