#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> f(n, -1);
  vector<int> b(n, -1);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i > 0) f[i] = max(f[i - 1], a[i]);
  }
  reverse(a.begin(), a.end());
  b[0] = a[0];
  for (int i = 0; i < n; i++) {
    if (i > 0) b[i] = max(b[i - 1], a[i]);
  }
  reverse(b.begin(), b.end());
  for (int i = 0; i < n; i++) {
    if (i == 0)
      cout << b[1] << endl;
    else if (i == n - 1)
      cout << f[n - 1] << endl;
    else
      cout << max(f[i - 1], b[i + 1]) << endl;
  }
  return 0;
}
