#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
int b[maxn];
int n;
bool cmp(int x, int y) { return x > y; }
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1, cmp);
  int maxx = b[1];
  int k = b[1];
  for (int i = 2; i <= n; i++)
    if (b[i] != maxx) {
      k = b[i];
      break;
    }
  for (int i = 1; i <= n; i++) {
    if (a[i] == maxx)
      printf("%d\n", k);
    else
      printf("%d\n", maxx);
  }
  return 0;
}
