#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const int MAX = 100100, LG = 20;
int arr[MAX];
set<pii> s;
bool lft[MAX], rght[MAX];
int solve(int idx) {
  auto it = s.upper_bound({arr[idx], 0});
  int high = it->second;
  int low = (--it)->second;
  s.insert({arr[idx], idx});
  if (!lft[high])
    return lft[high] = 1, arr[high];
  else
    return rght[low] = 1, arr[low];
}
int main() {
  int n;
  cin >> n;
  lft[0] = rght[0] = 1;
  lft[n + 1] = rght[n + 1] = 1;
  s.insert({0, 0});
  s.insert({1 << 30, n + 1});
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    int ret = solve(i);
    if (i != 1) printf("%d ", ret);
  }
  puts("");
  return 0;
}
