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