#include <iostream>
#include <cstdio>
using namespace std;
const int N = 1E5 + 10;
int stk[N], tt;
int main(){
int n; cin >> n;
tt = 0, stk[tt] = -1;
while(n -- ){
int tmp; scanf("%d", &tmp);
while(stk[tt] >= tmp) tt -- ;
cout << stk[tt] << " ";
stk[ ++ tt] = tmp;
}
return 0;
}