#include <bits/stdc++.h>
using namespace std;
int main() {
  long int N;
  cin >> N;
  long int A[N], max = -1, num;
  for (long int i = 0; i < N; i++) {
    cin >> A[i];
    if (max < A[i]) {
      max = A[i];
      num = i;
    }
  }
  bool MAX = false;
  for (long int i = 0; i < N; i++) {
    if (A[i] == max && i != num) MAX = true;
  }
  long int B[N], max2 = 0;
  for (long int i = 0; i < N; i++) {
    if (MAX) {
      for (long int j = 0; j < N; j++) {
        if (A[j] > max2 && A[j] < max) max2 = A[j];
      }
      B[i] = max2;
    } else {
      B[i] = max;
    }
  }
  for (long int o : B) cout << o << endl;
}
