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