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