#include <bits/stdc++.h>
using namespace std;
int N;
int T[100010][4];
set<pair<int, int> > S;
int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    int v;
    scanf("%d", &v);
    auto itr = S.insert(make_pair(v, -i)).first;
    if (i == 1) continue;
    itr++;
    if (itr != S.end() && T[(-itr->second)][1] == 0) {
      T[i][0] = (itr->first);
      T[(-itr->second)][1] = v;
    }
    itr--;
    if (itr != S.begin()) {
      itr--;
      if (T[(-itr->second)][2] == 0) {
        T[i][0] = (itr->first);
        T[(-itr->second)][2] = v;
      }
    }
  }
  for (int i = 2; i <= N; i++) printf("%d%c", T[i][0], i == N ? '\n' : ' ');
  return 0;
}
