#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a[200005], b[20005], n, ans1;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = a[i];
  }
  sort(a, a + n + 1);
  ans1 = a[n];
  for (int i = 0; i <= n; i++) {
    if (a[i] == a[n]) {
      a[i] = 0;
    }
  }
  sort(a, a + n);
  for (int i = 1; i <= n; i++) {
    if (b[i] == ans1 && a[i] != 0) {
      printf("%d", a[n]);
    } else {
      printf("%d", ans1);
    }
  }
}
