#include <bits/stdc++.h>
using namespace std;
int a[500009];
int b[500009];
int c[500009];
map<int, int> mp;
int main() {
  int n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  for (i = 0; i < n - 1; i++) {
    c[b[i]] = b[n - 1];
    mp[b[i]]++;
  }
  mp[b[n - 1]]++;
  c[b[n - 1]] = b[n - 2];
  for (i = 0; i < n; i++) {
    if (mp[a[i]] > 0) {
      if (mp[a[i]] == 1)
        cout << c[a[i]];
      else {
        cout << a[i];
        mp[a[i]]--;
      }
    } else
      cout << c[a[i]];
    cout << endl;
  }
}
