#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A(n), pre(n), suf(n);
  for (int i = 0; i < n; i++) cin >> A[i];
  if (n == 1) {
    cout << A[0];
    return 0;
  }
  int max1 = 0, max2 = 0;
  for (int i = 0; i < n; i++) {
    max1 = max(max1, A[i]);
    pre[i] = max1;
  }
  for (int i = n - 1; i >= 0; i--) {
    max2 = max(max2, A[i]);
    suf[i] = max2;
  }
  for (int i = 0; i < n; i++) {
    if (i != 0 && i != n - 1) cout << max(pre[i - 1], suf[i + 1]) << endl;
  }
}
