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