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