#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int n, a[N], f[N], b[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    f[i] = max(f[i - 1], a[i]);
  }
  for (int i = n - 1; i >= 0; --i) b[i] = max(b[i + 1], a[i]);
  cout << b[1] << '\n';
  for (int i = 1; i < n - 1; ++i) cout << max(b[i + 1], a[i - 1]) << '\n';
  cout << a[n - 2];
  return 0;
}
