#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int num[n];
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int af_sort[n];
  for (int i = 0; i < n; i++) {
    af_sort[i] = num[i];
  }
  int t;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (af_sort[i] < af_sort[j]) {
        t = af_sort[i];
        af_sort[i] = af_sort[j];
        af_sort[j] = t;
      }
    }
  }
  int check = (af_sort[0] == af_sort[1]) ? 1 : 0;
  if (check == 1) {
    for (int i = 0; i < n; i++) {
      cout << af_sort[0] << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      if (num[i] == af_sort[0]) {
        t = i;
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == t) {
        cout << af_sort[1];
      } else {
        cout << af_sort[0];
      }
      cout << endl;
    }
  }
  return 0;
}
