#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
signed main()
{
int n;
cin >> n;
stack<int> a;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
while (!a.empty() && a.top() >= x)
a.pop();
if (!a.empty())
cout << a.top() << " ";
else
cout << -1 << " ";
a.push(x);
}