#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  int maxa1 = 0;
  int maxa2 = 0;
  for (auto&& ai : a) {
    std::cin >> ai;
    if (ai > maxa1) {
      maxa2 = maxa1;
      maxa1 = ai;
    }
  }
  for (auto&& ai : a) std::cout << (ai == maxa1 ? maxa2 : maxa1) << std::endl;
}
