#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  int ma2 = -1;
  for (int i = n - 1; i >= 0; i--) {
    if (a[i] < a[n - 1]) {
      ma2 = a[i];
      break;
    }
  }
  if (ma2 == -1) ma2 = a[n - 1];
  for (int i = 0; i < n; i++) {
    if (b[i] == a[n - 1]) {
      cout << ma2;
    } else
      cout << a[n - 1];
    cout << " ";
  }
}
