#include <bits/stdc++.h>
int main() {
  long n;
  std::cin >> n;
  long *a = new long[n];
  for (long i = (0); i < (n); i++) std::cin >> a[i];
  long atmax, atmax2, max;
  if (a[0] > a[1]) {
    atmax = 0;
    atmax2 = 1;
    max = a[0];
  } else {
    atmax = 1;
    atmax2 = 0;
    max = a[1];
  }
  for (long i = (2); i < (n); i++)
    if (max < a[i]) {
      max = a[i];
      atmax2 = atmax;
      atmax = i;
    }
  for (long i = (0); i < (n); i++)
    if (i != atmax)
      std::cout << a[atmax] << std::endl;
    else
      std::cout << a[atmax2] << std::endl;
  return 0;
}
