#include <bits/stdc++.h>
using namespace std;
const int N = 100003;
int n, a[N], b[N];
int maxx = -1, maxi;
signed main(void) {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
    if (maxx < a[i]) {
      maxx = a[i];
      maxi = i;
    }
  }
  sort(b + 1, b + n + 1);
  for (int i = 1; i <= n; ++i) {
    if (i != maxi)
      printf("%d\n", b[n]);
    else
      printf("%d\n", b[n - 1]);
  }
  return 0;
}
