#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) { return x == 0 ? 1 : log10(x) + 1; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.push_back({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.push_back({n, 1});
  }
  return result;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
void debugV(const vector<T> v) {
  (void)v;
}
signed main() {
  ll N;
  cin >> N;
  vll A(N);
  ll max = 0;
  ll max2 = 0;
  for (ll i = 0; i < (ll)(N); ++i) {
    ll a;
    cin >> a;
    A[i] = a;
    if (i == 0) {
      max2 = a;
      max = a;
      continue;
    }
    if (max <= a) {
      max2 = max;
      max = a;
      continue;
    }
    if (max2 < a) {
      max2 = a;
    }
  }
  for (ll i = 0; i < (ll)(N); ++i) {
    ll a = A[i];
    if (a == max) {
      cout << (max2) << endl;
      continue;
    }
    cout << (max) << endl;
  }
  return 0;
}
