#include <bits/stdc++.h>
const int Maxn = 2e5;
std::multiset<int> S;
int a[Maxn];
int main() {
  register int i, j;
  int n, x;
  S.clear();
  std::cin >> n;
  for (i = 1; i <= n; ++i) {
    std::cin >> a[i];
    S.insert(a[i]);
  }
  for (i = 1; i <= n; ++i) {
    int num = S.erase(a[i]) - 1;
    for (j = 1; j <= num; ++j) S.insert(a[i]);
    std::cout << *--S.end() << "\n";
    S.insert(a[i]);
  }
  return 0;
}
