#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  int max_el, imax_el, ind;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (i == 0)
      max_el = a;
    else if (a > max_el) {
      imax_el = max_el;
      max_el = a;
      ind = i;
    } else if (a > imax_el)
      imax_el = a;
  }
  for (int i = 0; i < n; i++) {
    if (i != ind)
      cout << max_el;
    else
      cout << imax_el;
    cout << endl;
  }
}
