#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), e(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  b[0] = a[0], e[n - 1] = a[n - 1];
  for (int i = 1; i < n; i++) b[i] = max(b[i - 1], a[i]);
  for (int i = n - 2; i >= 0; i--) e[i] = max(b[i + 1], a[i]);
  printf("%d\n", e[1]);
  for (int i = 1; i < n - 1; i++) printf("%d\n", max(b[i - 1], e[i + 1]));
  printf("%d\n", b[n - 2]);
  return 0;
}
