#include <bits/stdc++.h>
int compareInt(const void* a, const void* b);
int main() {
  int N, D, i, j, a, b, c, keta, count, r;
  int aa[200000];
  int bb[200000];
  for (i = 0; i < 200000; i++) {
    aa[200000] = 0;
    bb[200000] = 0;
  }
  a = 0;
  b = 0;
  scanf("%d", &N);
  for (i = 1; i <= N; i++) {
    scanf("%d", &aa[i - 1]);
    bb[i - 1] = aa[i - 1];
  }
  qsort(aa, 200000, sizeof(int), compareInt);
  for (i = 199999; 199999 - N < i; i--) {
    if (aa[199999] != aa[i]) {
      b = aa[i];
      a = 1;
      break;
    }
  }
  if (a == 0) {
    b = aa[199999];
  }
  for (i = 0; i < N; i++) {
    if (bb[i] != aa[199999]) {
      printf("%d", aa[199999]);
    } else {
      printf("%d", b);
    }
  }
  return (0);
}
int compareInt(const void* a, const void* b) {
  int aNum = *(const int*)a;
  int bNum = *(const int*)b;
  if (aNum < bNum) {
    return -1;
  } else if (aNum > bNum) {
    return 1;
  }
  return 0;
}
