#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int i, j, k;
int main() {
  ll n, max = 0, max2;
  cin >> n;
  vector<ll> a(n);
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (max < a[i]) {
      max = a[i];
    }
  }
  vector<ll> ans(n, max);
  ll key = -1;
  max2 = -1;
  bool allmax = true;
  for (i = 0; i < n; i++) {
    if (max2 < a[i] && a[i] != max) {
      max2 = a[i];
    }
    if (a[i] == max) {
      key = i;
    }
  }
  if (max2 != -1) {
    ans[key] = max2;
  }
  for (i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
