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