#include <bits/stdc++.h>
using namespace std;
int father[111111], num[111111];
map<int, int> ma, maa, idd;
struct st {
  int nod[2], val;
} tree2[111111];
int root = 1, cnt = 2;
struct Tree {
  int l, r;
  int index;
  int minnum;
} tree[111111 << 2];
void build(int l, int r, int index) {
  tree[index].l = l, tree[index].r = r;
  if (l == r) {
    tree[index].minnum = ma[num[l]];
    return;
  }
  int mid = (l + r) / 2;
  build(l, mid, index << 1);
  build(mid + 1, r, index << 1 | 1);
  tree[index].minnum =
      min(tree[index << 1].minnum, tree[index << 1 | 1].minnum);
}
int query(int l, int r, int index) {
  if (tree[index].l == l && tree[index].r == r) {
    return tree[index].minnum;
  }
  int mid = (tree[index].l + tree[index].r) / 2;
  if (r <= mid) {
    return query(l, r, index << 1);
  } else if (l > mid) {
    return query(l, r, index << 1 | 1);
  } else {
    return min(query(l, mid, index << 1), query(mid + 1, r, index << 1 | 1));
  }
}
void dfs(int l, int r, int x, int c) {
  if (l > r) return;
  int temp = query(l, r, 1);
  father[temp] = maa[x];
  int mid = idd[temp];
  dfs(l, mid - 1, temp, 0);
  dfs(mid + 1, r, temp, 1);
}
int main() {
  int n, i;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &num[i]);
    ma[num[i]] = i;
    maa[i] = num[i];
  }
  int root = num[1];
  sort(&num[1], &num[1] + n);
  int flag = i;
  build(1, n, 1);
  for (i = 1; i <= n; i++) {
    idd[ma[num[i]]] = i;
  }
  for (i = 1; i <= n; i++) {
    if (num[i] == root) {
      flag = i;
      if (i - 1 >= 1) dfs(1, i - 1, ma[root], 0);
      if (i + 1 <= n) dfs(i + 1, n, ma[root], 1);
      break;
    }
  }
  for (i = 2; i <= n; i++) {
    printf("%d ", father[i]);
  }
  return 0;
}
