#include <bits/stdc++.h>
int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N);
  for (auto& a : A) {
    std::cin >> a;
  }
  int max;
  int better;
  auto tmp = A;
  std::sort(tmp.begin(), tmp.end());
  std::vector<int> result;
  std::unique_copy(tmp.begin(), tmp.end(), std::back_inserter(result));
  max = result.back();
  result.pop_back();
  better = result.back();
  for (auto& a : A) {
    if (a != max) {
      std::cout << max << std::endl;
    } else {
      std::cout << better << std::endl;
    }
  }
  return 0;
}
