#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  std::vector<int> array;
  for (int i = 0; i < n; i++) {
    cin >> a;
    array.push_back(a);
  }
  std::vector<size_t> indices(array.size());
  std::iota(indices.begin(), indices.end(), 0);
  std::sort(indices.begin(), indices.end(),
            [&array](size_t i1, size_t i2) { return array[i1] < array[i2]; });
  int count = 0;
  for (auto v : indices) {
    if (count == array.size() - 1) {
      cout << array[indices[array.size() - 2]];
    } else {
      cout << array[indices[array.size() - 1]];
    }
    count++;
  }
}
