#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926;
template <typename T>
T gcd(T a, T b) {
  while (b) {
    T c = a % b;
    a = b;
    b = c;
  }
  return a;
}
template <typename T>
T lcm(T a, T b) {
  assert(a / gcd(a, b) <= numeric_limits<T>::max() / b);
  return a * (b / gcd(a, b));
}
class out {
 public:
  template <typename T>
  out &operator()(const T &t) {
    cout << t << ' ';
    return *this;
  }
  template <typename T1, typename T2>
  out &operator()(const pair<T1, T2> &t) {
    cout << '(' << t.first << ',' << t.second << ')' << ' ';
    return *this;
  }
};
template <typename iter>
inline void print_(iter beg, iter end) {
  for_each(beg, end, out());
  cout << endl;
}
template <typename T>
inline void print_(const T &t) {
  cout << t << endl;
}
inline void print_(const char *fmt, ...) {
  va_list va;
  va_start(va, fmt);
  vprintf(fmt, va);
  va_end(va);
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N]) {
  for (unsigned int i = 0; i < M; ++i) {
    for (unsigned int j = 0; j < N; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T, unsigned int M, unsigned int N>
inline void print_(const T (&t)[M][N], unsigned int r, unsigned int c) {
  for (unsigned int i = 0; i < r; ++i) {
    for (unsigned int j = 0; j < c; ++j) {
      cout << t[i][j] << ' ';
    }
    cout << endl;
  }
}
template <typename T>
inline int BKDRHash(const T *str) {
  register int hash = 0;
  while (int ch = (int)*str++) {
    hash = hash * 131 + ch;
  }
  return hash;
}
inline unsigned long long powxy(unsigned long long x, int y = 2) {
  unsigned long long r;
  for (r = 1; y > 0; --y) r *= x;
  return r;
}
inline unsigned long long factorial(unsigned long long n) {
  unsigned long long r;
  for (r = 1; n > 0; --n) r *= n;
  return r;
}
inline unsigned long long permutation(unsigned long long n,
                                      unsigned long long k) {
  unsigned long long r = 1;
  while (k--) r *= n--;
  return r;
}
inline unsigned long long combination(unsigned long long n,
                                      unsigned long long k) {
  return permutation(n, k) / factorial(k);
}
inline string tostr(int i) {
  ostringstream is;
  is << i;
  return is.str();
}
int n;
vector<char> lv, rv;
struct node {
  int left;
  int right;
  int v;
  node(int v) : v(v) {
    left = lv.size();
    lv.push_back(0);
    right = rv.size();
    rv.push_back(0);
  }
};
struct cmp : public binary_function<const node &, const node &, bool> {
  bool operator()(const node &n1, const node &n2) { return n1.v < n2.v; }
};
set<node, cmp> s;
int main() {
  int v1;
  scanf("%d%d", &n, &v1);
  clock_t start = clock();
  s.insert(node(v1));
  for (int i = 1; i < n; ++i) {
    int v;
    scanf("%d", &v);
    set<node, cmp>::iterator iter = s.insert(node(v)).first;
    set<node, cmp>::iterator pre = iter;
    --pre;
    set<node, cmp>::iterator nxt = iter;
    ++nxt;
    if (iter == s.begin() || rv[pre->right]) {
      lv[nxt->left] = 1;
      printf("%d ", nxt->v);
    } else {
      rv[pre->right] = 1;
      printf("%d ", pre->v);
    }
    if (clock() - start >= 1900) break;
  }
  return 0;
}
