#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;
    if (i > 0 && a >= max_el) {
      imax_el = max_el;
      max_el = max(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;
    if (i != n - 1)
      cout << ' ';
    else
      cout << endl;
  }
}
