#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n;
int main() {
  cin >> n;
  vector<int> a(n + 1);
  vector<int> r(n + 1), l(n + 1);
  for (int i = 0; i < (n); i++) cin >> a[i];
  l[0] = a[0];
  r[n - 1] = a[n - 1];
  for (int i = 0; i < n; ++i) l[i + 1] = max(l[i], a[i + 1]);
  for (int i = n - 1; i >= 0; --i) r[i] = max(r[i + 1], a[i]);
  cout << r[0] << endl;
  for (int i = 1; i < n - 1; ++i) cout << max(l[i - 1], r[i + 1]) << endl;
  cout << l[n - 1] << endl;
  return 0;
}
