#include <bits/stdc++.h>
using namespace std;
char IO;
inline int rd() {
  int res = 0;
  while ((IO = getchar()) && (IO < '0' || IO > '9'))
    ;
  while (IO >= '0' && IO <= '9')
    res = (res << 1) + (res << 3) + (IO ^ 48), IO = getchar();
  return res;
}
int n, d;
int a[200005];
int main() {
  n = rd();
  int first = -1, second = -1;
  for (register int i = 1, _n = n; i <= _n; ++i) {
    a[i] = rd();
    if (a[i] > first)
      second = first, first = a[i];
    else if (a[i] > second)
      second = first;
  }
  for (register int i = 1, _n = n; i <= _n; ++i) {
    if (a[i] == first)
      printf("%d\n", second);
    else
      printf("%d\n", first);
  }
  return 0;
}
