#include <bits/stdc++.h>
int main() {
  int N, A[200000], a, B[200000];
  int max = 0;
  int max2 = 0;
  scanf("%d", &N);
  for (int i = 0; i <= N - 1; i++) {
    scanf("%d", &A[i]);
    if (A[i] > max) {
      max = A[i];
    }
  }
  for (int j = 0; j <= N - 1; j++) {
    if (A[j] != max) {
      printf("%d\n", max);
    } else {
      a = A[j];
      A[j] = 0;
      for (int k = 0; k <= N - 1; k++) {
        B[k] = A[k];
        if (B[k] > max2) {
          max2 = B[k];
        }
      }
      printf("%d\n", max2);
      A[j] = a;
    }
  }
}
