#include <bits/stdc++.h>
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T>
void chmin(T& a, const T& b) {
  a = min(a, b);
}
template <class T>
void chmax(T& a, const T& b) {
  a = max(a, b);
}
void yes() {
  cout << "Yes" << endl;
  exit(0);
}
void no() {
  cout << "No" << endl;
  exit(0);
}
int main() {
  int n;
  cin >> n;
  vint a(n);
  for (int i = (0); i < (n); ++i) cin >> a[i];
  int mx1 = 0, mx2 = 0;
  for (int i = (0); i < (n); ++i) {
    if (a[mx1] < a[i]) {
      mx1 = i;
    }
  }
  for (int i = (0); i < (n); ++i) {
    if (i != mx1 && a[mx2] < a[i]) mx2 = i;
  }
  for (int i = (0); i < (n); ++i) {
    if (i == mx1) {
      cout << a[mx2] << endl;
    } else {
      cout << a[mx1] << endl;
    }
  }
  return 0;
}
