#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int maximum = 0;
  int smaximum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  vector<int> S = A;
  sort(S.begin(), S.end());
  reverse(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    if (A.at(i) != S.at(0)) {
      cout << A.at(i) << endl;
    } else {
      cout << S.at(1) << endl;
    }
  }
  return 0;
}
