#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long modpow(long long a, long long x) {
  if (a < 0) a += MOD;
  long long ans = 1;
  while (x > 0) {
    if (x & 1) ans = ans * a % MOD;
    a = a * a % MOD;
    x >>= 1;
  }
  return ans;
}
long long gyaku(long long n) { return modpow(n, MOD - 2); }
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long max1 = 0, max2 = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    if (max1 < a[i]) {
      max2 = max1;
      max1 = a[i];
    }
    if (max1 > a[i] && max2 < a[i]) {
      max2 = a[i];
    }
  }
  for (long long i = 0; i < (long long)(n); i++) {
    if (a[i] == max1) {
      cout << max2 << endl;
    } else
      cout << max1 << endl;
  }
}
