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