#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int N;
  int A[200000];
  int max;
  cin >> N;
  for (int i = 0; i < (int)(N); i++) cin >> A[i];
  max = 0;
  int max_i = -1;
  int max_tmp = 0;
  for (int i = 0; i < (int)(N); i++) {
    max = max_tmp;
    if (A[i] < max && max_i != i) {
      cout << max << endl;
      break;
    } else {
      max_tmp = max;
      max = -1;
      for (int j = 0; j < (int)(N); j++) {
        if (i != j) {
          if (chmax(max, A[j])) max_i = j;
        }
      }
    }
    cout << max << endl;
  }
  return 0;
}
