#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};
int n;
int a[1000];
int b[1000][2];
int maxv;
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    maxv = max(maxv, a[i]);
    b[i][0] = maxv;
  }
  maxv = 0;
  for (int i = n - 1; i >= 0; --i) {
    maxv = max(maxv, a[i]);
    b[i][1] = maxv;
  }
  for (int i = 0; i < n; ++i) {
    if (i == 0) {
      cout << b[1][1] << endl;
    } else if (i == n - 1) {
      cout << b[n - 2][0] << endl;
    } else {
      cout << max(b[i - 1][0], b[i + 1][1]) << endl;
    }
  }
  return 0;
}
