#include <bits/stdc++.h>
using namespace std;
int arr[1000007];
int main() {
  int i, j, n, h, sh;
  scanf("%d", &n);
  h = -1;
  sh = -1;
  for (i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    if (arr[i] > h) {
      h = arr[i];
    }
    if (h > arr[i] && sh < arr[i]) sh = arr[i];
  }
  if (sh == -1) sh = h;
  for (i = 0; i < n; i++) {
    if (h == arr[i])
      printf("%d\n", sh);
    else
      printf("%d\n", h);
  }
  return 0;
}
