#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, a, n, maks = 0, maks2 = 0, catat;
  bool sama = false;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a;
    if (a == maks) {
      sama = true;
    } else if (a > maks) {
      maks2 = maks;
      maks = a;
      catat = i;
      sama = false;
    } else if (((a > maks2) && (a <= maks)) || sama) {
      maks2 = a;
    }
  }
  for (i = 0; i < n; i++) {
    if (i == catat) {
      cout << maks2 << endl;
      continue;
    }
    cout << maks << endl;
  }
  return 0;
}
