#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  for (int j = 0; j < n; j++) {
    int reg;
    int max = -1;
    reg = vec.at(j);
    vec.at(j) = 0;
    for (int p = 0; p < n - 1; p++) {
      if (vec.at(p) <= vec.at(p + 1) && max <= vec.at(p + 1))
        max = vec.at(p + 1);
      if (vec.at(p) >= vec.at(p + 1) && max <= vec.at(p)) max = vec.at(p);
    }
    vec.at(j) = reg;
    cout << max << endl;
  }
}
