#include <bits/stdc++.h>
using namespace std;
int main() {
  set<int> gr;
  set<int> sm;
  map<int, int> minP;
  map<int, int> maxP;
  int n;
  cin >> n;
  int a;
  cin >> a;
  sm.insert(a);
  gr.insert(-1 * a);
  minP[a] = -1;
  maxP[a] = 1000000001;
  bool ok = false;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    int paiMa = -1;
    int minMa = -1;
    int maxMa = -1;
    if (gr.upper_bound(-1 * a) != gr.end()) {
      paiMa = -1 * (*(gr.upper_bound(-1 * a)));
      minMa = minP[paiMa];
      maxMa = maxP[paiMa];
    }
    int paiMe = -1;
    if (sm.upper_bound(a) != sm.end()) {
      paiMe = *(sm.upper_bound(a));
    }
    if (ok) {
      cout << " ";
    }
    if (a < maxMa && a > minMa) {
      cout << paiMa;
      minP[a] = paiMa;
      maxP[a] = maxP[paiMa];
      gr.erase(paiMa * -1);
    } else {
      cout << paiMe;
      maxP[a] = paiMe;
      minP[a] = minP[paiMe];
      sm.erase(paiMe);
    }
    ok = true;
    sm.insert(a);
    gr.insert(-1 * a);
  }
  cout << endl;
  return 0;
}
