#include <bits/stdc++.h>
int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int array[N];
  for (int i = 0; i < N; i++) {
    scanf("%d", &array[i]);
  }
  int index1, index2, index3;
  int max, sec, th = 0;
  for (int i = 0; i < N; i++) {
    if (max <= array[i]) {
      max = array[i];
      index1 = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (sec <= array[i] && i != index1) {
      sec = array[i];
      index2 = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (th <= array[i] && i != index1 && index3 != i) {
      th = array[i];
      index3 = th;
    }
  }
  for (int i = 0; i < N; i++) {
    if (index1 == i) {
      printf("%d\n", sec);
    } else if (index2 == i) {
      printf("%d\n", th);
    } else {
      printf("%d\n", max);
    }
  }
  return 0;
}
