#include <iostream>
#include <stack>
#include <vector>
using namespace std;
stack<int> s;
vector<int> x;
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i ++ )
{
int tmp;
cin >> tmp;
x.push_back(tmp);
while (s.size() && s.top() >= x[i]) s.pop();
if (s.size()) cout << s.top() << ' ';
else cout << -1 << ' ';
s.push(x[i]);
}
return 0;
}