#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  int maximum = 0;
  int smaximum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) > maximum) {
      smaximum = maximum;
      maximum = A.at(i);
    } else if (A.at(i) == maximum) {
      continue;
    } else if (A.at(i) >= smaximum) {
      smaximum = A.at(i);
    }
  }
  bool same = true;
  for (int i = 1; i < N; i++) {
    if (A.at(i) == A.at(i - 1)) {
      continue;
    }
    same = false;
    break;
  }
  if (same) {
    for (int i = 0; i < N; i++) {
      cout << A.at(i) << endl;
    }
  } else {
    for (int i = 0; i < N; i++) {
      if (A.at(i) == maximum) {
        cout << smaximum << endl;
      } else {
        cout << maximum << endl;
      }
    }
  }
  return 0;
}
