#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int first = 0, second = 0, count = 0;
  for (int i = 0; i < n; i++) {
    first = max(first, a.at(i));
  }
  for (int i = 0; i < n; i++) {
    if (first != a.at(i)) {
      count++;
    } else {
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    if (i != count) {
      second = max(second, a.at(i));
    }
  }
  cout << second << endl;
}
