#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e12;
const int MAXN = 1e5 + 1, MODM = 1e9 + 7, P = 1e6 + 3, MULT1 = 30, MULT2 = 239,
          LUCKY = 13, ELEVEN = 11, MAXM = 101;
map<int, int> ans;
set<int> lf, rr;
set<int> mas;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  lf.insert(a[0]);
  rr.insert(a[0]);
  mas.insert(a[0]);
  for (int i = 1; i < n; i++) {
    auto r = mas.upper_bound(a[i]);
    if (r == mas.end()) {
      r--;
      int c = *r;
      if (rr.count(c)) {
        cout << c << " ";
        rr.erase(c);
      }
    } else {
      int c = *r;
      if (lf.count(c)) {
        cout << c << " ";
        lf.erase(c);
      } else {
        --r;
        c = *r;
        cout << c << " ";
        rr.erase(c);
      }
    }
    mas.insert(a[i]);
    lf.insert(a[i]);
    rr.insert(a[i]);
  }
  return 0;
}
