#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n + 1];
  long long i, b[n + 1];
  memset(a, 0, sizeof(a));
  for (i = 1; i <= n; i++) cin >> a[i];
  for (i = 1; i <= n; i++) {
    if (a[i + 1] > a[i - 1] && i + 1 <= n)
      b[i] = a[i + 1];
    else
      b[i] = a[i - 1];
  }
  for (i = 1; i <= n; i++) cout << b[i] << endl;
  return 0;
}
