#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
void Open() {}
const int N = 100010;
int sta[N];
int a[N];
int b[N];
int L[N], R[N], ans[N];
struct node {
  int l, r, ma, mi;
} lt[N * 8];
void pushup(int x) {
  lt[x].ma = max(lt[(x << 1)].ma, lt[(x << 1 | 1)].ma);
  lt[x].mi = min(lt[(x << 1)].mi, lt[(x << 1 | 1)].mi);
}
void build(int l, int r, int x) {
  lt[x] = (node){l, r, -INF, INF};
  if (l == r) {
    lt[x] = (node){l, r, b[l], b[l]};
    return;
  }
  build(l, ((lt[x].l + lt[x].r) / 2), (x << 1));
  build(((lt[x].l + lt[x].r) / 2) + 1, r, (x << 1 | 1));
  pushup(x);
}
int querymi(int l, int r, int x) {
  if (lt[x].l >= l && lt[x].r <= r) {
    return lt[x].mi;
  }
  if (r <= ((lt[x].l + lt[x].r) / 2))
    return querymi(l, r, (x << 1));
  else if (l > ((lt[x].l + lt[x].r) / 2))
    return querymi(l, r, (x << 1 | 1));
  else
    return min(querymi(l, ((lt[x].l + lt[x].r) / 2), (x << 1)),
               querymi(((lt[x].l + lt[x].r) / 2) + 1, r, (x << 1 | 1)));
}
void update(int idx, int x) {
  if (lt[x].l == idx && lt[x].r == idx) {
    lt[x].ma = -INF;
    lt[x].mi = INF;
    return;
  }
  if (idx <= ((lt[x].l + lt[x].r) / 2))
    update(idx, (x << 1));
  else if (idx > ((lt[x].l + lt[x].r) / 2))
    update(idx, (x << 1 | 1));
  pushup(x);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]), sta[i] = a[i];
  sort(sta, sta + n);
  for (int i = 0; i < n; i++)
    a[i] = lower_bound(sta, sta + n, a[i]) - sta + 1, b[a[i]] = i;
  build(1, n, 1);
  priority_queue<int, vector<int>, greater<int> > que;
  que.push(0);
  update(a[0], 1);
  for (int i = 0; i < n; i++) L[i] = 1, R[i] = n;
  while (!que.empty()) {
    int ci = que.top();
    que.pop();
    int l = L[ci], r = R[ci];
    int miid = INF, maid = INF;
    if (l <= a[ci]) miid = querymi(l, a[ci], 1);
    if (a[ci] <= r) maid = querymi(a[ci], r, 1);
    if (miid != INF) {
      ans[miid] = a[ci];
      L[miid] = max(L[miid], L[ci]);
      R[miid] = min(R[miid], a[ci]);
      update(a[miid], 1);
      que.push(miid);
    }
    if (maid != INF) {
      ans[maid] = a[ci];
      L[maid] = max(L[maid], a[ci]);
      R[maid] = min(R[maid], R[ci]);
      update(a[maid], 1);
      que.push(maid);
    }
  }
  for (int i = 1; i < n; i++)
    printf("%d%c", sta[ans[i] - 1], " \n"[i == n - 1]);
  return 0;
}
