#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, A[200000];
  int tmp[2] = {-1};
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> *(A + i);
  }
  int max;
  int j;
  for (int i = 0; i < N; i++) {
    if (tmp[1] != -1 && tmp[1] != i) {
      cout << tmp[0] << endl;
      tmp[1] = -1;
      continue;
    }
    max = i == 0 ? *(A + 1) : *(A);
    for (j = 1; j < N; j++) {
      if (*(A + j) > max && i != j) {
        max = *(A + j);
        tmp[1] = j;
      }
    }
    cout << max << endl;
    tmp[0] = max;
  }
  return 0;
}
