#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int buff, i;
  int n;
  vector<int> seq;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> buff;
    seq.push_back(buff);
  }
  int max = *max_element(seq.begin(), seq.end());
  sort(seq.begin(), seq.end());
  int indent;
  for (i = 0; i < n; i++) {
    if (max == seq[i]) {
      indent = i;
      break;
    }
  }
  for (i = 0; i < n; i++) {
    if (indent != i + 1)
      cout << max << '\n';
    else
      cout << seq[1] << '\n';
  }
  cout << endl;
  return 0;
}
