#include <bits/stdc++.h>
using namespace std;
int main() {
  int A[200000], N, max, max2, maxcout, i, j;
  cin >> N;
  for (i = 1; i < N + 1; i++) {
    cin >> A[i];
  }
  max = A[2];
  maxcout = 0;
  for (i = 2; i < N; i++) {
    if (A[i + 1] > max) {
      max = A[i + 1];
    } else if (A[i + 1] == max) {
      maxcout++;
    }
  }
  cout << max << endl;
  for (j = 2; j < N + 1; j++) {
    if (A[j] == max && maxcout == 0) {
      max2 = A[1];
      for (i = 1; i < N; i++) {
        if (A[i + 1] > max2 && A[i + 1] < max) {
          max2 = A[i + 1];
        }
      }
      cout << max2 << endl;
    } else {
      cout << max << endl;
    }
  }
}
