#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  int array[n];
  for (i = 0; i < n; i++) {
    cin >> array[i];
  }
  int max1 = 0;
  int max2 = 0;
  for (int i = 0; i < n; i++) {
    if (array[i] >= max1) {
      max2 = max1;
      max1 = array[i];
    } else if (array[i] > max2 && array[i] < max1) {
      max2 = array[i];
    }
  }
  for (int i = 0; i < n; i++) {
    if (array[i] == max1)
      cout << max2;
    else
      cout << max1;
  }
}
