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