#include <bits/stdc++.h>
using namespace std;
int a[100005], p[100005];
map<int, int> Min;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  set<int> stL, stR;
  stL.insert(a[1]);
  stR.insert(a[1]);
  Min[a[1]] = -1e9;
  for (int i = 2; i <= n; ++i) {
    set<int>::iterator it = stL.lower_bound(a[i]);
    if (it != stL.end() && (Min[*it] == -1e9 || Min[*it] < a[i])) {
      p[i] = *it;
      Min[a[i]] = Min[*it];
      stL.erase(it);
      stL.insert(a[i]);
      stR.insert(a[i]);
    } else {
      set<int>::iterator it2 = stR.lower_bound(a[i]);
      it2--;
      p[i] = *it2;
      Min[a[i]] = *it2;
      stR.erase(it2);
      stL.insert(a[i]);
      stR.insert(a[i]);
    }
  }
  for (int i = 2; i <= n; ++i) cout << p[i] << ' ';
}
