#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12);
  int64_t n;
  cin >> n;
  vector<int> a(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<int, int> added;
  for (int64_t i = 0; i < n; i++) {
    map<int, int>::iterator iter = added.lower_bound(a[i]);
    if (iter != added.end()) {
      int l1 = iter->second;
      int p1 = iter->first;
      if (iter == added.begin()) {
        cout << p1 << " ";
        added[a[i]] = l1 + 1;
      } else {
        iter--;
        int l2 = iter->second;
        int p2 = iter->first;
        if (l1 > l2) {
          cout << p1 << " ";
          added[a[i]] = l1 + 1;
        } else {
          cout << p2 << " ";
          added[a[i]] = l2 + 1;
        }
      }
    } else {
      map<int, int>::reverse_iterator iter = added.rbegin();
      if (iter != added.rend()) {
        cout << iter->first << " ";
        added[a[i]] = iter->first + 1;
      } else {
        added[a[i]] = 0;
      }
    }
  }
  return 0;
}
