#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> A;
  vector<int> res;
  cin >> N;
  A.resize(N);
  res.resize(N);
  for (size_t idx = 0; idx < N; ++idx) {
    cin >> A[idx];
  }
  vector<int>::iterator m_itr = max_element(A.begin(), A.end());
  int dist = distance(A.begin(), m_itr);
  int maxima = *m_itr;
  int sub = -1;
  for (size_t i = 0; i < N; ++i) {
    if (i == dist)
      continue;
    else if (A[i] > sub) {
      sub = A[i];
    } else
      continue;
  }
  A[dist] = sub;
  for (size_t i = 0; i < N; ++i) {
    cout << A[i] << endl;
  }
  return 0;
}
