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