#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int m0 = *max_element(a.begin(), a.begin() + i),
        m1 = *max_element(a.begin() + i + 1, a.end());
    if (m0 > m1)
      cout << m0 << endl;
    else
      cout << m1 << endl;
  }
  return 0;
}
