#include <bits/stdc++.h>
int findSec(std::vector<int> a, int max) {
  int rtn = a[0];
  for (int i = 1; i < a.size(); i++) {
    if (rtn < a[i] && a[i] != max) rtn = a[i];
  }
  return rtn;
}
int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
  int max = *max_element(a.begin(), a.end());
  int maxsec = findSec(a, max);
  for (int i = 0; i < n; i++) {
    if (a[i] != max) {
      std::cout << max << std::endl;
    } else {
      std::cout << maxsec << std::endl;
    }
  }
}
