#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d;
  cin >> n;
  int *a = new int[n];
  int *b = new int[n];
  int ma = -1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    b[i] = a[i];
  }
  sort(b, b + n);
  int j = n - 1;
  while (b[j] == b[n - 1]) {
    j--;
  }
  int firstmax = b[n - 1];
  int secondmax = b[j];
  for (int i = 0; i < n; i++) {
    if (a[i] != b[n - 1]) {
      cout << firstmax << endl;
    } else {
      cout << secondmax << endl;
    }
  }
}
