#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
  cin >> N;
  int A[N + 1];
  for (int i = 0; i < N; ++i) cin >> A[i];
  int max_i = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] > A[max_i]) max_i = i;
  }
  int max2 = 0;
  for (int i = 0; i < N; ++i) {
    if (i == max_i) continue;
    if (A[i] > A[max2]) max2 = i;
  }
  for (int i = 0; i < N; i++) {
    if (i == max_i)
      cout << A[max2] << endl;
    else
      cout << A[max_i] << endl;
  }
}
