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