#include <bits/stdc++.h>
using namespace std;
int n, k, mn, mx;
unordered_map<int, int> d;
set<int> nums;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  nums.insert(k);
  mn = mx = k;
  d[k] = 0;
  for (int i = 1; i < n; i++) {
    cin >> k;
    if (k < mn) {
      cout << mn << '\n';
      mn = k;
    } else if (k > mx) {
      cout << mx << '\n';
      mx = k;
    } else {
      set<int>::iterator one = nums.lower_bound(k);
      set<int>::iterator two = one--;
      int lo = *one, hi = *two;
      cout << (d[lo] > d[hi] ? lo : hi) << '\n';
    }
    nums.insert(k);
    d[k] = i;
  }
  return 0;
}
