#include<iostream>
#include<stack>
using namespace std;
stack<int> a;
int main()
{
int n;
cin >> n;
for(int i = 0 ; i < n; i++)
{
int x;
cin >> x;
// 第一个元素比较 3前面没有数字 输出-1
if(a.empty())
{
a.push(x) ;
cout << -1 << ' ';
}
else if( a.top() < x)
{
cout << a.top() << ' ';
a.push(x);
}
else
{
while( !a.empty() && x <= a.top())
{
a.pop();
}
if(a.empty()) cout << -1 << ' ';
else cout << a.top() << ' ';
a.push(x);
}
}
return 0;
}