#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, m = 0, ms = 0, im;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (a > m) {
      m = a;
      im = i + 1;
    } else if (a <= m && a > ms)
      ms = a;
  }
  for (int i = 0; i < n; i++) cout << (i != im ? m : ms) << endl;
  return 0;
}
