#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long int n;
  cin >> n;
  unsigned long int x[n], y[2];
  cin >> x[0];
  y[0] = x[0];
  if (n > 1) {
    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("%ld\n", y[0]) : std::printf("%ld\n", y[1]);
  }
  return 0;
}
