#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int max_ = A[0];
  int max_arg = 0;
  for (int i = 0; i < N; ++i) {
    if (A[i] > max_) max_arg = i;
  }
  int max_next = min(A[0], A[1]);
  int max_next_arg = 0;
  for (int i = 0; i < N; ++i) {
    if (i == max_arg) {
    } else {
      if (A[i] == max_next) max_next_arg = i;
    }
  }
  if (max_arg == max_next_arg) {
    for (int i = 0; i < N; ++i) cout << max_ << endl;
  } else {
    for (int i = 0; i < N; ++i) {
      if (i == max_arg)
        cout << max_next << endl;
      else
        cout << max_ << endl;
    }
  }
  return 0;
}
