#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int max_1 = -1e6, max_2 = -1e6, max_1_idx, max_2_idx;
  for (int i = 0; i < N; i++) {
    if (A[i] > max_1) {
      max_1 = A[i];
      max_1_idx = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i != max_1_idx) {
      if (A[i] > max_2) {
        max_2 = A[i];
        max_2_idx = i;
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == max_1_idx) {
      cout << max_1 << endl;
    } else {
      cout << max_2 << endl;
    }
  }
  return 0;
}
