#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int best_max = 0;
  int best_max_idx = 0;
  int second_max = 0;
  int second_max_idx = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    if (A.at(i) > best_max) {
      best_max = A.at(i);
      best_max_idx = i;
    } else if (A.at(i) > second_max) {
      second_max = A.at(i);
      second_max_idx = i;
    }
  }
  for (int i = 0; i < N; i++) {
    if (best_max_idx != i) {
      cout << best_max << endl;
    } else {
      cout << second_max_idx << endl;
    }
  }
}
