#include <bits/stdc++.h>
int main(void) {
  int n, k, i, r, d, cou = 0, tmp, len, m, max = 0, premax = 0;
  long long mod = 1000000007;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf(" %d", &a[i]);
    if (max < a[i])
      premax = max, max = a[i], cou = 0;
    else if (max == a[i] && premax < a[i])
      premax = a[i], cou++;
    else if (max == a[i])
      cou++;
    else if (premax < a[i])
      premax = a[i];
  }
  if (cou > 0)
    for (i = 0; i < n; i++) printf("%d\n", a[i]);
  else {
    for (i = 0; i < n; i++) {
      if (a[i] == max)
        printf("%d\n", premax);
      else
        printf("%d\n", max);
    }
  }
  return 0;
}
