#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n);
  for (int i = 0; i < n; i++) {
    std::cin >> v[i];
  }
  std::vector<int> tmp = v;
  std::sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    if (v[0] == tmp[i])
      std::cout << v[1] << std::endl;
    else
      std::cout << v[0] << std::endl;
  }
}
