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