#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
const vector<ll> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A[i];
  }
  ll m = 0, m2 = 0;
  for (ll i = 1; i < N; ++i) {
    if (A[i] > A[m]) {
      m2 = m;
      m = i;
    } else if (A[i] > A[m2]) {
      m2 = i;
    }
  }
  ll ans1 = A[m], ans2 = A[m2];
  for (ll count = 0; count < N; ++count) {
    if (count == m) {
      cout << ans2 << endl;
    } else {
      cout << ans1 << endl;
    }
  }
}
