#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ul = unsigned long long;
using ii = pair<int, int>;
const ll mod7 = 1000000007, mod = 1000000000, OO = 0x3f3f3f3f;
const ld EPS = 1e-7;
double Pi = acos(-1);
const ld rad = Pi / 180.0;
ll power(ll x, ll y, ll p) {
  ll res = 1;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll nCr(ll n, ll m) { return (m == 0) ? 1 : n * nCr(n - 1, m - 1) / m; }
int main() {
  int n, mx1 = -1, mx2 = -1;
  cin >> n;
  int a[n], b[n];
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  mx1 = a[n - 1];
  for (int i = n - 1; i >= 0; --i) {
    if (a[i] < mx1) {
      mx2 = a[i];
      break;
    }
  }
  if (mx2 == -1) mx2 = a[n - 2];
  for (int i = 0; i < n; ++i) {
    if (b[i] != mx1) {
      cout << mx1 << "\n";
    } else {
      cout << mx2 << "\n";
    }
  }
  return 0;
}
