#include <bits/stdc++.h>
using namespace std;
int n;
int a[200010];
int b[200010], c[200010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  b[0] = a[0];
  for (int i = 1; i < n; i++) b[i] = max(b[i - 1], a[i]);
  c[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; i--) c[i] = max(c[i + 1], a[i]);
  for (int i = 0; i < n; i++) {
    int t = -1e9;
    if (i) t = max(t, a[i - 1]);
    if (i != n - 1) t = max(t, a[i + 1]);
    cout << t << "\n";
  }
  return 0;
}
