#include <bits/stdc++.h>
int main(void) {
  int N, i;
  int* A;
  scanf("%d", &N);
  A = (int*)malloc(sizeof(int) * N);
  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  int first = 0;
  for (i = 0; i < N - 1; i++) {
    if (A[i + 1] > A[i]) {
      first = i + 1;
    }
  }
  int second;
  if (first != 0) {
    second = 0;
  } else {
    second = 1;
  }
  for (i = 0; i < first - 2; i++) {
    if (A[i + 1] > A[i]) {
      second = i + 1;
    }
  }
  if (0 < first < N - 1) {
    if (A[first + 1] > A[first - 1]) {
      second = first + 1;
    }
  }
  for (i = first + 1; i < N - 1; i++) {
    if (A[i + 1] > A[i]) {
      second = i + 1;
    }
  }
  for (i = 0; i < N; i++) {
    if (i != first) {
      printf("%d\n", A[first]);
    } else {
      printf("%d\n", A[second]);
    }
  }
  free(A);
  return 0;
}
