#include <bits/stdc++.h>
using namespace std;
long long const MOD = 1e9 + 7;
int const inf = 1e9;
long long const INF = 1e18;
inline void ios_() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}
template <typename T>
int size(const T& a) {
  return (int)a.size();
}
template <typename T>
T Div(T a, T b) {
  return (a + b - 1) / b;
}
template <typename T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  int ma = -inf, p = -1;
  for (int(i) = 0; (i) < (n); (i)++) {
    cin >> v[i];
    if (chmax(ma, v[i])) p = i;
  }
  vector<int> u(v);
  sort((u).begin(), (u).end());
  for (int(i) = 0; (i) < (n); (i)++) {
    cout << (i == p ? u[1] : ma) << endl;
  }
  return 0;
}
