#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int A[N];
  priority_queue<int> q;
  cin >> N;
  for (int i = 0; i < (int)(N); i++) {
    int kazu;
    cin >> kazu;
    A[i] = kazu;
    q.push(kazu);
  }
  int atai = 0;
  for (int i = 0; i < (int)(N); i++) {
    atai = q.top();
    q.pop();
    if (A[i] == atai) {
      int atai2 = atai;
      atai = q.top();
      q.pop();
      cout << atai << endl;
      q.push(atai2);
      q.push(atai);
    } else {
      cout << atai << endl;
      q.push(atai);
    }
  }
  return 0;
}
