#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  long long a[n];
  long long f = 0;
  long long s = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    if (a[i] >= a[f]) {
      s = f;
      f = i;
    } else if (a[i] >= a[s]) {
      s = i;
    }
  }
  for (long long i = 0; i < (long long)(n); i++) {
    i == f ? cout << a[s] << endl : cout << a[f] << endl;
  }
}
