#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  vector<int> L(n), R(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  L[0] = a[0];
  for (int i = 1; i < n; ++i) L[i] = max(L[i - 1], a[i]);
  R[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) R[i] = max(R[i + 1], a[i]);
  vector<int> ret(n);
  ret[0] = R[1];
  ret[n - 1] = L[n - 1];
  for (int i = 1; i < n - 1; ++i) {
    ret[i] = max(L[i - 1], R[i + 1]);
  }
  for (int i = 0; i < n; ++i) {
    printf("%d\n", ret[i]);
  }
  return 0;
}
