#include <bits/stdc++.h>
using namespace std;
struct TSparseTable {
  static const int LOG = 20;
  vector<int> Log;
  vector<vector<int>> T;
  TSparseTable(const vector<int>& a)
      : Log(a.size() + 1), T(LOG, vector<int>(a.size())) {
    for (int i = 0; i < (int)a.size(); ++i) T[0][i] = a[i];
    for (int i = 1; i < LOG; ++i)
      for (int j = 0; j + (1 << (i - 1)) < (int)a.size(); ++j)
        T[i][j] = min(T[i - 1][j], T[i - 1][j + (1 << (i - 1))]);
    for (int i = 1; i < (int)Log.size(); ++i) {
      int j = 0;
      while ((1 << (j + 1)) < i) ++j;
      Log[i] = j;
    }
  }
  int Get(int l, int r) const {
    int log = Log[r - l];
    return min(T[log][l], T[log][r - (1 << log)]);
  }
};
void Find(int x, int l, int r, const vector<int>& p,
          const TSparseTable& sparseTable, vector<int>& ans) {
  stack<tuple<int, int, int>> s;
  s.push(make_tuple(x, l, r));
  while (!s.empty()) {
    int x = get<0>(s.top());
    int l = get<1>(s.top());
    int r = get<2>(s.top());
    s.pop();
    int lft = -1;
    int rft = -1;
    if (x > l) {
      int y = p[sparseTable.Get(l, x)];
      if (y != x) {
        ans[y] = x;
        lft = y;
      }
    }
    if (x + 1 < r) {
      int y = p[sparseTable.Get(x + 1, r)];
      if (y != x) {
        ans[y] = x;
        rft = y;
      }
    }
    if (lft != -1) s.push(make_tuple(lft, l, x));
    if (rft != -1) s.push(make_tuple(rft, x + 1, r));
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> b = a;
  sort(b.begin(), b.end());
  vector<int> p(n);
  for (int i = 0; i < n; ++i)
    p[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
  vector<int> pos(n);
  for (int i = 0; i < n; ++i) pos[p[i]] = i;
  TSparseTable sparseTable(pos);
  vector<int> ans(n);
  Find(p[0], 0, n, p, sparseTable, ans);
  for (int i = 1; i < n; ++i) cout << b[ans[p[i]]] << ' ';
  cout << endl;
  return 0;
}
