#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, j;
  cin >> n;
  long long a[n];
  set<long long> s;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    s.insert(a[i]);
  }
  set<long long>::iterator it, itt;
  for (i = 0; i < n; i++) {
    it = s.end();
    itt = s.begin();
    itt--;
    it--;
    while (*it == a[i]) {
      it--;
      if (it == itt) {
        break;
      }
    }
    if (it == itt)
      cout << a[i] << endl;
    else
      cout << *it << endl;
  }
}
