include [HTML_REMOVED]
using namespace std;
//栈顶元素比要加进去的元素小的话,将栈顶元素输出
//栈顶元素比要加进去的元素大的话,弹出栈顶元素
const int N=100010;
int m,tt;
int st[N];
int main(){
cin>>m;
while(m–){
int x;
cin>>x;
while(tt&&st[tt]>=x) tt–;
if(tt) cout<<st[tt]<<” “;
else cout<<”-1”<<” “;
st[++tt]=x;
}
return 0;
}