#include <bits/stdc++.h>
using namespace std;
int A[200000];
int N;
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[i] = a;
  }
  int firstMax, secondMax;
  firstMax = 0;
  secondMax = 0;
  for (int i = 1; i < N; i++) {
    if (A[firstMax] < A[i]) {
      secondMax = firstMax;
      firstMax = i;
    }
    if (A[secondMax] < A[i] && i != firstMax) {
      secondMax = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (i != firstMax) {
      cout << A[firstMax] << endl;
    } else {
      cout << A[secondMax] << endl;
    }
  }
  return 0;
}
