#include <bits/stdc++.h>
int main() {
  int n;
  scanf("%d", &n);
  int *array = (int *)malloc(sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }
  int max, nextMax;
  int maxIndex;
  if (array[0] > array[1]) {
    max = array[0];
    maxIndex = 0;
    nextMax = array[1];
  } else {
    max = array[1];
    maxIndex = 1;
    nextMax = array[0];
  }
  for (int i = 2; i < n; i++) {
    if (max < array[i]) {
      nextMax = max;
      max = array[i];
      maxIndex = i;
    } else if (nextMax < array[i]) {
      nextMax = array[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == maxIndex)
      printf("%d\n", max);
    else
      printf("%d\n", nextMax);
  }
  return 0;
}
