#include <bits/stdc++.h>
using namespace std;
set<int> all_used, has_left, has_right;
int n;
int a[111111];
vector<int> ans;
void solve() {
  all_used.clear();
  has_left.clear();
  has_right.clear();
  ans.clear();
  has_left.insert(a[0]);
  has_right.insert(a[0]);
  all_used.insert(a[0]);
  for (int i = 1; i < n; ++i) {
    int first = a[i];
    auto it = all_used.lower_bound(first);
    if (it != all_used.end() && has_left.count(*it)) {
      ans.push_back(*it);
      has_left.erase(has_left.find(*it));
    } else {
      --it;
      ans.push_back(*it);
      has_right.erase(has_right.find(*it));
    }
    has_left.insert(first);
    has_right.insert(first);
    all_used.insert(first);
  }
}
map<int, int> cl, cr;
vector<int> nans;
void naive() {
  nans.clear();
  cl.clear();
  cr.clear();
  cl[a[0]] = -1;
  cr[a[0]] = -1;
  for (int i = 1; i < n; ++i) {
    int cur = a[0];
    while (1) {
      if (a[i] < cur) {
        if (cl[cur] == -1) {
          cl[cur] = a[i];
          break;
        } else {
          cur = cl[cur];
        }
      } else {
        if (cr[cur] == -1) {
          cr[cur] = a[i];
          break;
        } else {
          cur = cr[cur];
        }
      }
    }
    nans.push_back(cur);
    cl[a[i]] = cr[a[i]] = -1;
  }
}
int inp[111111];
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    inp[i] = a[i];
  }
  sort(inp, inp + n);
  for (int i = 0; i < n; ++i) {
    a[i] = lower_bound(inp, inp + n, a[i]) - inp;
  }
  solve();
  for (int i = 0; i < (int)(ans).size(); ++i) {
    if (i) printf(" ");
    printf("%d", inp[ans[i]]);
  }
  printf("\n");
}
