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