#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, item;
  cin >> n;
  vector<int> parent(n + 1);
  set<int> S;
  set<int>::iterator it1, it2, temp;
  map<int, pair<bool, bool>> M;
  for (i = 1; i <= n; ++i) {
    cin >> item;
    it1 = S.upper_bound(item);
    if (it1 != S.end()) {
      it2 = it1;
      --it2;
    }
    if (it1 == S.end()) {
      if (!S.empty()) {
        temp = S.end();
        --temp;
        parent[i] = *temp;
        M[*temp].second = true;
      }
    } else if (it2 == S.end()) {
      if (!S.empty()) {
        temp = S.begin();
        parent[i] = *temp;
        M[*temp].first = true;
      }
    } else {
      if (!M[*it1].first) {
        parent[i] = *it1;
        M[*it1].first = true;
      } else if (!M[*it2].second) {
        parent[i] = *it2;
        M[*it2].second = true;
      }
    }
    S.insert(item);
  }
  copy(parent.begin() + 2, parent.end(), ostream_iterator<int>(cout, " "));
  cout << endl;
  return 0;
}
