#include <bits/stdc++.h>
int main(void) {
  int n, a[200000];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int max = 0;
  for (int i = 0; i < n; i++) {
    if (max < a[i]) max = a[i];
  }
  int b[200000];
  for (int i = 0; i < n; i++) {
    if (a[i] != max)
      b[i] = a[i];
    else
      b[i] = 0;
  }
  int sec_max = 0;
  for (int i = 0; i < n; i++) {
    if (sec_max < b[i]) sec_max = b[i];
  }
  if (sec_max == 0) sec_max = max;
  for (int i = 0; i < n; i++) {
    if (a[i] == max)
      printf("%d\n", sec_max);
    else
      printf("%d\n", max);
  }
  return 0;
}
