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