#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = (0), iformax = (n); i < iformax; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a.begin(), a.end());
  int mx = a[n - 1];
  for (int j = (0), jformax = (n); j < jformax; j++) {
    if (b[j] = mx) {
      cout << a[n - 2];
    } else {
      cout << mx << endl;
    }
  }
  return 0;
}
