#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
map<int, int> mymap;
int tree[3 * 100000 + 7];
pair<int, int> arr[100000 + 7], arr2[100000 + 7], tr[100000 + 7];
void update(int node, int l, int r, int p) {
  if (r < p or l > p) return;
  if (l == r) {
    tree[node] = 1;
    return;
  }
  int lft = 2 * node, rgt = lft + 1, mid = (l + r) / 2;
  update(lft, l, mid, p);
  update(rgt, mid + 1, r, p);
  tree[node] = tree[lft] + tree[rgt];
}
int query(int node, int l, int r, int i, int j) {
  if (l > j or r < i) return 0;
  if (l >= i and r <= j) return tree[node];
  int lft = 2 * node, rgt = lft + 1, mid = (l + r) / 2;
  return query(lft, l, mid, i, j) + query(rgt, mid + 1, r, i, j);
}
int index_q(int node, int l, int r, int sum) {
  if (l == r) return l;
  int lft = 2 * node, rgt = lft + 1, mid = (l + r) / 2;
  if (tree[lft] >= sum)
    return index_q(lft, l, mid, sum);
  else
    return index_q(rgt, mid + 1, r, sum - tree[lft]);
}
int main() {
  int n, s, id, rg;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i].first);
    arr[i].second = i;
    arr2[i] = arr[i];
  }
  sort(arr, arr + n);
  for (int i = 0; i < n; i++) mymap[arr[i].first] = i + 1;
  update(1, 1, n, mymap[arr2[0].first]);
  for (int i = 1; i < n; i++) {
    s = query(1, 1, n, 1, mymap[arr2[i].first]);
    if (i - 1) printf(" ");
    if (s == 0) {
      rg = index_q(1, 1, n, s + 1);
      printf("%d", arr[rg - 1].first);
      tr[rg].first = 1;
    } else {
      id = index_q(1, 1, n, s);
      if (tr[id].second == 0) {
        printf("%d", arr[id - 1].first);
        tr[id].second = 1;
      } else {
        rg = index_q(1, 1, n, s + 1);
        printf("%d", arr[rg - 1].first);
        tr[id].first = 1;
      }
    }
    update(1, 1, n, mymap[arr2[i].first]);
  }
  printf("\n");
  return 0;
}
