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