#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using P = pair<int, int>;
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> num(200010);
  for (int i = 0; i < (int)(N); i++) {
    int tmp;
    cin >> tmp;
    A[i] = tmp;
    num[tmp]++;
  }
  for (int i = 0; i < (int)(N); i++) {
    num[A[i]]--;
    for (int j = 200010; j >= 2; j--) {
      if (num[j] > 0) {
        cout << j << endl;
        break;
      }
    }
    num[A[i]]++;
  }
  return 0;
}
