#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long(i) = 0; (i) < (n); (i)++) {
    cin >> a.at(i);
  }
  cout << *max_element(a.begin() + 1, a.end()) << endl;
  for (long long(i) = 0; (i) < (n - 2); (i)++) {
    long long ma, mb;
    ma = *max_element(a.begin(), a.begin() + i);
    mb = *max_element(a.begin() + 2, a.end());
    if (ma < mb) {
      cout << mb << endl;
      ;
    } else {
      cout << ma << endl;
    }
  }
  cout << *max_element(a.begin(), a.end() - 1) << endl;
  return 0;
}
