#include <bits/stdc++.h>
int main(void) {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int max = a[0];
  int max_i;
  for (int i = 1; i < n; i++) {
    if (max < a[i]) {
      max = a[i];
      max_i = i;
    }
  }
  a[max_i] = 0;
  int max2 = a[0];
  for (int i = 1; i < n; i++) {
    if (max2 < a[i]) {
      max2 = a[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == max_i)
      printf("%d ", max2);
    else
      printf("%d ", max);
  }
  return 0;
}
