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