#include <bits/stdc++.h>
using namespace std;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int vec[200002];
  multiset<int> map;
  int max = -1;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    vec[i] = a;
    map.insert(a);
    if (a > max) max = a;
  }
  auto begin = map.begin();
  for (int i = 0; i < n; ++i) {
    int key = vec[i];
    if (key < max) {
      cout << max << endl;
    } else {
      if (map.count(key) > 1) {
        cout << key << endl;
      } else {
        auto it = map.find(key);
        if (it != begin) it--;
        cout << *it << endl;
      }
    }
  }
  return 0;
}
