#include <bits/stdc++.h>
using namespace std;
void max_print(int a[], int n) {
  int max_num = a[0];
  for (int i = 0; i < n; i++) {
    if (max_num == a[i]) {
      max_num = 0;
      for (int j = 0; j < n; j++) {
        if (j != i) {
          max_num = max(max_num, a[j]);
        }
      }
    } else if (max_num < a[i - 1]) {
      max_num = a[i - 1];
    }
    cout << max_num << "\n";
  }
}
int main(void) {
  int n, a[200000];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  max_print(a, n);
  return 0;
}
