#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, max, m_idx, s_max, s_m_idx;
  cin >> N;
  vector<long long> v(N);
  max = 0;
  m_idx = 0, s_max = 0, s_m_idx = 0;
  for (long long i = 0; i < N; i++) {
    cin >> v[i];
    if ((i != 0) && (v[i] > v[m_idx])) {
      s_max = max;
      s_m_idx = m_idx;
      max = v[i];
      m_idx = i;
    } else if ((i != 0) && (v[i] < v[m_idx]) && (v[i] >= v[s_m_idx])) {
      s_max = v[i];
      s_m_idx = i;
    }
  }
  for (long long i = 0; i < N; i++) {
    if (i == m_idx) {
      cout << v[s_m_idx] << endl;
    } else {
      cout << v[m_idx] << endl;
    }
  }
  return 0;
}
