#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  vector<int> a, b, mem(200000, 0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    b.push_back(tmp);
  }
  a = b;
  for (int i = 0; i < a.size(); i++) {
    if (mem[a[i]] != 0) {
      cout << mem[a[i]] << endl;
    } else {
      int tmp = a[i];
      a[i] = INT_MIN;
      mem[tmp] = *std::max_element(a.begin(), a.end());
      cout << mem[tmp] << endl;
    }
    a = b;
  }
  return 0;
}
