#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n), c(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  b[0] = -1;
  for (int i = 1; i < n; ++i) {
    b[i] = max(b[i - 1], a[i]);
  }
  c[n - 1] = -1;
  for (int i = n - 2; i >= 0; --i) {
    c[i] = max(c[i + 1], a[i]);
  }
  for (int i = 0; i < (n); ++i) {
    cout << max(b[i], c[i]) << endl;
  }
}
