#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, mx = 0, nx = 0;
  vector<long long> arr(200001);
  cin >> n;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
    arr[x] = x;
    if (x == mx) {
      nx++;
    }
    mx = max(mx, x);
  }
  for (long long i = 0; i < n; i++) {
    if (arr[v[i]] != mx) {
      cout << mx;
    } else {
      if (nx > 0) {
        cout << mx << endl;
      } else {
        for (long long j = arr[mx] - 1; j >= 0; j--) {
          if (arr[j] != 0) {
            cout << arr[j] << endl;
            break;
          }
        }
      }
    }
  }
  return 0;
}
