#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n], s[n];
  for (int i = 0; i < n; i++) {
    s[i] = 0;
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    if (i != 0 && i != n - 1) {
      for (int j = 0; j < i; j++)
        if (a[j] > s[i]) s[i] = a[j];
      for (int j = i + 1; j < n; j++)
        if (a[j] > s[i]) s[i] = a[j];
    } else if (i == 0) {
      for (int j = 1; j < n; j++)
        if (a[j] > s[i]) s[i] = a[j];
    } else if (i == n - 1) {
      for (int j = 0; j < n - 1; j++)
        if (a[j] > s[i]) s[i] = a[j];
    }
    cout << s[i] << endl;
  }
}
