#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> va(n), vl(n), vr(n);
  for (int i = 0; i < n; i++) cin >> va[i];
  vl[0] = va[0];
  for (int i = 1; i < n; i++) vl[i] = max(vl[i - 1], va[i]);
  vr[n - 1] = va[n - 1];
  for (int i = n - 1; i >= 0; i--) vr[i] = max(vr[i + 1], va[i]);
  cout << vr[1] << "\n";
  for (int i = 1; i < n - 1; i++) cout << max(vl[i - 1], vr[i + 1]) << "\n";
  cout << vl[n - 1] << "\n";
}
