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