#include <bits/stdc++.h>
using namespace std;
int main(int, char**) {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (long i = 0; i < N; ++i) {
    if (i == N - 1) {
      cout << *max_element(A.begin(), A.begin() + i) << endl;
    } else {
      cout << max(*max_element(A.begin(), A.begin() + i),
                  *max_element(A.begin() + i + 1, A.end()))
           << endl;
    }
  }
  return 0;
}
