#include <bits/stdc++.h>
int main(void) {
  int length_seq;
  int current_term;
  int current_max;
  int current_max_idx = 0;
  int next_max;
  int next_max_idx = 1;
  scanf("%d", &length_seq);
  scanf("%d", &current_max);
  scanf("%d", &next_max);
  if (current_max < next_max) {
    int temp = current_max;
    current_max = next_max;
    next_max = temp;
    current_max_idx = 1;
    next_max_idx = 0;
  }
  assert(length_seq >= 2);
  assert(length_seq <= 200000);
  for (int i = 1; i < length_seq; i++) {
    scanf("%d", &current_term);
    if (current_term > current_max) {
      next_max = current_max;
      next_max_idx = current_max_idx;
      current_max = current_term;
      current_max_idx = i;
    }
    if (current_term > next_max) {
      next_max = current_term;
      next_max_idx = i;
    }
  }
  for (int i = 0; i < length_seq; i++) {
    if (i == current_max_idx) {
      printf("%d\n", next_max);
    } else {
      printf("%d\n", current_max);
    }
  }
}
