#include <bits/stdc++.h>
int main() {
  int N;
  scanf("%d", &N);
  int A[N];
  for (int i = 0; i < N; i += 1) {
    scanf("%d", &A[i]);
  }
  int max = 1;
  int max_index = 1;
  int max_number = 0;
  int second_max = 1;
  for (int i = 0; i < N; i += 1) {
    if (A[i] > max) {
      max = A[i];
      max_index = i;
      max_number = 1;
    } else if (A[i] == max) {
      max_number += 1;
    }
  }
  for (int i = 0; i < N; i += 1) {
    if (A[i] < max && A[i] > second_max) {
      second_max = A[i];
    }
    printf("%d ", second_max);
  }
  if (max_number > 1) {
    for (int i = 0; i < N; i += 1) {
      printf("%d\n", max);
    }
  } else {
    for (int i = 0; i < N; i += 1) {
      if (i == max_index) {
        printf("%d\n", second_max);
      } else {
        printf("%d\n", max);
      }
    }
  }
  return 0;
}
