#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100001, INF = 100000001;
struct node {
  long long int l, r;
  node operator+(const node &a) {
    node nw;
    nw.l = min(l, a.l);
    nw.r = max(r, a.r);
    return nw;
  }
};
node T[MaxN * 4];
long long int H[MaxN], V[MaxN], N;
node query(int x) {
  long long int p = 1, q = N + 1, r = 1, i;
  while (p + 1 < q) {
    if ((p + q) / 2 <= x)
      p = (p + q) / 2, r = r * 2 + 1;
    else
      q = (p + q) / 2, r = r * 2;
  }
  node k;
  k.l = 0, k.r = INF;
  for (; r > 1; r /= 2) {
    if (r % 2)
      k.l = max(k.l, T[r - 1].r);
    else
      k.r = min(k.r, T[r + 1].l);
  }
  return k;
}
void update(int x) {
  long long int p = 1, q = N + 1, r = 1, i;
  while (p + 1 < q) {
    if ((p + q) / 2 <= x)
      p = (p + q) / 2, r = r * 2 + 1;
    else
      q = (p + q) / 2, r = r * 2;
  }
  T[r].l = T[r].r = x;
  for (r /= 2; r; r /= 2) T[r] = T[r * 2] + T[r * 2 + 1];
}
int insertar(int x) {
  node P = query(x);
  int i, j, p = 0, q;
  if (P.r < INF) {
    if (P.l)
      p = (H[P.r] < H[P.l] ? P.l : P.r);
    else
      p = P.r;
  } else if (P.l)
    p = P.l;
  H[x] = H[p] + 1;
  update(x);
  return V[p];
}
void in(int x, int y, int n) {
  T[n].l = INF, T[n].r = 0;
  if (x + 1 == y) return;
  in(x, (x + y) / 2, n * 2);
  in((x + y) / 2, y, n * 2 + 1);
}
void hashear(vector<int> &A) {
  vector<pair<int, int> > C;
  int i, j, p, q;
  for (i = 0; i < N; i++) C.push_back(make_pair(A[i], i));
  sort(C.begin(), C.end());
  for (i = 0; i < N; i++) {
    V[i + 1] = C[i].first;
    A[C[i].second] = i + 1;
  }
}
int main() {
  int i, j, p, q;
  cin >> N;
  in(1, N + 1, 1);
  vector<int> A(N);
  for (i = 0; i < N; i++) cin >> A[i];
  hashear(A);
  insertar(A[0]);
  for (i = 1; i < N; i++) cout << insertar(A[i]) << " ";
}
