#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.at(i);
  }
  vector<int> max_ex(N);
  int true_max;
  true_max = A.at(0);
  for (int i = 1; i < N; i++) {
    true_max = max(true_max, A.at(i));
  }
  for (int i = 0; i < N; i++) {
    if (A.at(i) == true_max) {
      int max_temp;
      for (int j = 0; j < N; j++) {
        if (j == i) {
          continue;
        }
        max_temp = max(max_temp, A.at(j));
      }
      max_ex.at(i) = max_temp;
    } else {
      max_ex.at(i) = true_max;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << max_ex.at(i) << endl;
  }
}
