#include <bits/stdc++.h>
using namespace std;
vector<int> temp;
int main() {
  int n;
  cin >> n;
  int mx = 0, pos = 0;
  for (int x = 0; x < n; x++) {
    int a;
    cin >> a;
    if (mx < a) {
      pos = x;
      mx = a;
    }
    temp.push_back(a);
  }
  sort(temp.begin(), temp.end());
  for (int x = 0; x < n; x++) {
    if (x - 1) {
      cout << " ";
    }
    if (x == pos) {
      cout << temp[1];
    } else {
      cout << mx;
    }
  }
  cout << endl;
}
