#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int max1, max2, cnt;
  vector<int> A(N), v(200000, 0);
  cnt = 0;
  max2 = 0;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) v[A[i] - 1]++;
  for (int i = 199999; i >= 0; i--) {
    if (v[i] > 1) {
      max1 = i + 1;
      break;
    } else if (v[i] == 1 and cnt == 0) {
      max1 = i + 1;
      cnt++;
    } else if (v[i] > 0 and cnt == 1) {
      max2 = i + 1;
      break;
    }
  }
  if (max2 == 0) {
    for (int i = 0; i < N; i++) cout << max1 << '\n';
  } else {
    for (int i = 0; i < N; i++) {
      if (A[i] == max1)
        cout << max2 << '\n';
      else
        cout << max1 << '\n';
    }
  }
}
