#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)5e5 + 47;
const int INF = (int)1e9;
struct Tree {
  int l, r, par, h;
  Tree() {
    l = r = par = -1;
    h = 0;
  }
};
Tree t[MAXN];
int a[MAXN];
set<pair<int, int> > st;
int n;
void add(int x, int id) {
  if (id == 0) {
    st.insert({x, id});
    return;
  }
  auto it = st.lower_bound({x, -1});
  auto lit = it;
  if (lit != st.begin()) lit--;
  int pp = -1, hh = -1;
  if (it != st.end() && t[it->second].h > hh)
    pp = it->second, hh = t[it->second].h;
  if (lit != st.end() && t[lit->second].h > hh)
    pp = lit->second, hh = t[lit->second].h;
  if (x < a[pp])
    t[pp].l = id;
  else
    t[pp].r = id;
  t[id].par = pp;
  t[id].h = t[pp].h + 1;
  st.insert({x, id});
}
void out() {
  for (int i = 1; i < n; i++) printf("%d ", a[t[i].par]);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    add(a[i], i);
  }
  out();
  return 0;
}
