#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    int max = 0;
    for (int j = 0; j < N; j++) {
      if (j == i) {
        continue;
      }
      if (j == i + 1) {
        max = A[j];
        continue;
      }
      if (j == 0) {
        max = A[j];
      }
      if (A[j] > A[j - 1]) {
        max = A[j];
      }
    }
    cout << max << endl;
  }
}
