#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
const int MAX = 1e3 + 5;
const long long MAX2 = 11;
const int MOD = 1000000000 + 7;
const long long INF = 20000;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1};
int n, y;
set<int> x, z, le, ri;
set<int>::iterator lw, up;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> y;
  x.insert(y);
  z.insert(-y);
  while (--n) {
    cin >> y;
    lw = z.upper_bound(-y);
    up = x.upper_bound(y);
    if (lw != z.end() && !le.count(*lw))
      cout << -*lw << " ", le.insert(*lw);
    else
      cout << *up << " ", ri.insert(*up);
    x.insert(y);
    z.insert(-y);
  }
  return 0;
}
