#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n], pre[n], post[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  pre[0] = a[0];
  post[n - 1] = a[n - 1];
  for (int i = 1; i < n; i++) pre[i] = max(pre[i - 1], a[i]);
  for (int i = n - 2; i >= 0; i--) post[i] = max(a[i], post[i + 1]);
  cout << pre[1] << '\n';
  for (int i = 1; i < n - 1; i++) {
    cout << max(pre[i - 1], post[i + 1]) << '\n';
  }
  cout << post[n - 2];
}
