#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, i, j, k, t, l;
  cin >> n;
  int a[n + 5], b[n + 5];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b, b + n);
  long long max = b[n - 1];
  for (i = 0; i < n; i++) {
    if (a[i] == max)
      cout << b[lower_bound(a, a + n, max) - a] << endl;
    else
      cout << max << endl;
  }
}
