#include <bits/stdc++.h>
int main(void) {
  int N;
  int max1 = 0, max2 = 0;
  int counter1;
  int number;
  scanf("%d", &N);
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &number);
    if (number > max1) {
      max1 = number;
      counter1 = i + 1;
    } else if (number > max2) {
      max2 = number;
    }
    for (size_t i = 0; i < N; i++) {
      if (i != counter1 - 1) {
        printf("%d\n", max1);
      } else
        printf("%d\n", max2);
    }
  }
}
