#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    A.at(i) = x;
    B.at(i) = x;
  }
  sort(B.begin(), B.end());
  if (B.at(0) == B.at(1)) {
    for (int i = 0; i < N; i++) {
      cout << B.at(0) << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A.at(i) == B.at(0))
        cout << B.at(1) << endl;
      else
        cout << B.at(0) << endl;
    }
  }
}
