#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, max = -99999;
  cin >> N;
  int* p = new int[N];
  int* q = new int[N];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
    if (p[i] > max) {
      q[i] = max;
      max = p[i];
      for (int j = 0; j < i; j++) {
        q[j] = max;
      }
    } else {
      q[i] = max;
      for (int j = 0; j < i; j++) {
        if (p[i] > q[j]) {
          q[j] = p[i];
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    cout << q[i] << endl;
  }
}
