#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> arr;
  for (int i = 0; i < n; i++) {
    int temp;
    scanf("%d", &temp);
    arr.push_back(temp);
  }
  for (int i = 0; i < n; i++) {
    int mx = -1;
    for (int j = 0; j < i; j++)
      if (arr[j] > mx) mx = arr[j];
    for (int j = i + 1; j < n; j++)
      if (arr[j] > mx) mx = arr[j];
    printf("%d\n", mx);
  }
}
