#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, a;
  vector<int> A;
  vector<int> V;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    A.push_back(a);
  }
  int max_num = *max_element(A.begin(), A.end());
  V.resize(A.size() - 1);
  for (int i = 0; i < N; i++) {
    if (A[i] == max_num) {
      copy(A.begin(), A.begin() + i, V.begin());
      copy(A.begin() + (i + 1), A.end(), back_inserter(V));
      int num = *max_element(V.begin(), V.end());
      cout << num << endl;
      V.erase(V.begin(), V.end());
    } else {
      cout << max_num << endl;
    }
  }
}
