#include <bits/stdc++.h>
int main(void) {
  int n, ma, mb, ma1, mb1;
  scanf("%d", &n);
  int num[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
  }
  ma = num[0];
  mb = 0;
  for (int l = 0; l < n; l++) {
    if (ma <= num[l]) {
      ma1 = ma;
      mb1 = mb;
      ma = num[l];
      mb = l;
    }
  }
  if (ma1 <= num[n - 1] && mb != n - 1) {
    ma1 = num[n - 1];
    mb1 = n;
  }
  for (int j = 0; j < n; j++) {
    if (j == mb) {
      printf("%d\n", ma1);
    } else {
      printf("%d\n", ma);
    }
  }
  return 0;
}
