#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
int main() {
  ull n;
  cin >> n;
  ;
  vector<ull> a(n);
  for (ull i = 0, i_len = (n); i < i_len; ++i) {
    cin >> a[i];
  };
  ull max1 = *std::max_element(a.begin(), a.end());
  for (ull i = 0, i_len = (n); i < i_len; ++i) {
    if (a[i] < max1) {
      cout << max1 << "\n";
    } else {
      cout << max(*std::max_element(a.begin(), a.begin() + i),
                  *std::max_element(a.begin() + i + 1, a.end()))
           << "\n";
    }
  }
}
