#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  vector<int> A(200002), B(200002);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }
  sort(A.begin(), A.end());
  if (A[0] == A[1]) {
    for (int i = 0; i < N; i++) cout << A[i] << endl;
  } else {
    vector<int>::iterator it = lower_bound(B.begin(), B.end(), A[0]);
    for (int i = 0; i < N; i++) {
      if (i == it - B.begin())
        cout << A[1] << endl;
      else
        cout << A[0] << endl;
    }
  }
}
