#include <bits/stdc++.h>
using ll = int64_t;
using namespace std;
ll gcd(ll a, ll b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  int n;
  cin >> n;
  bool ok = true;
  vector<int> p(n);
  int ma1 = 0, ma2 = 0, a;
  for (int i = 0; i < (n); ++i) cin >> p[i];
  a = p[n - 1];
  for (int i = 0; i < (n - 1); ++i) {
    if (a != p[i]) {
      ok = false;
      break;
    }
  }
  if (ok) {
    for (int i = 0; i < (n); ++i) cout << p[0] << endl;
    return 0;
  }
  for (int i = 0; i < (n); ++i) {
    ma1 = max(ma1, p[i]);
  }
  for (int i = 0; i < (n); ++i) {
    if (p[i] == ma1) continue;
    ma2 = max(ma2, p[i]);
  }
  for (int i = 0; i < (n); ++i) {
    if (p[i] == ma1)
      cout << ma2 << endl;
    else
      cout << ma1 << endl;
  }
  return 0;
}
