#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int x[n], y[2];
  cin >> x[0];
  y[0] = x[0];
  for (int i = 1; i < n; i++) {
    cin >> x[i];
    if (x[i] >= y[0]) {
      y[1] = x[0];
      y[0] = x[i];
    } else if (x[i] > y[1]) {
      y[1] = x[i];
    }
  }
  for (int i = 0; i < n; i++) {
    (x[i] != y[0]) ? std::printf("%d\n", y[0]) : std::printf("%d\n", y[1]);
  }
  return 0;
}
