#include <bits/stdc++.h>
int main(void) {
  int n;
  int a[200000] = {};
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  int first, fi;
  int second;
  if (a[0] >= a[1]) {
    first = a[0];
    fi = 0;
    second = a[1];
  } else {
    first = a[1];
    fi = 1;
    second = a[0];
  }
  for (int i = 2; i < n; i++) {
    if (a[i] >= first) {
      second = first;
      first = a[i];
      fi = i;
    } else if (a[i] >= second) {
      second = a[i];
    }
  }
  for (int i = 0; i < n - 1; i++) {
    printf("%d\n", i != fi ? first : second);
  }
  return 0;
}
