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