#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  int a[200011];
  int b[200011];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[i] = a[i];
  }
  for (int j = 0; j < n - 1; j++) {
    for (int k = j + 1; k < n; k++) {
      if (b[j] < b[k]) {
        int tmp = b[j];
        b[j] = b[k];
        b[k] = tmp;
      }
    }
  }
  for (int l = 0; l < n; l++) {
    if (a[l] == b[0]) {
      cout << b[1];
    } else {
      cout << b[0];
    }
  }
  return 0;
}
