#include <bits/stdc++.h>
int main() {
  int n;
  std::cin >> n;
  std::map<int, int> a;
  int val;
  for (int i = 0; i < n; ++i) {
    std::cin >> val;
    a[val] = i;
  }
  int max = a.rbegin()->first;
  for (int i = 0; i < n; ++i) {
    int ans = max;
    if (a.at(max) == i) {
      std::map<int, int>::reverse_iterator rit = a.rbegin();
      ++rit;
      ans = rit->first;
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
