#include <bits/stdc++.h>
using namespace std;
bool comp(int a, int b) { return a > b; }
int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  vector<int> A, B;
  A.resize(N);
  B.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  B = A;
  sort(A.begin(), A.end(), comp);
  int max = A[0];
  int ans;
  for (int n : B) {
    if (n < max) {
      ans = max;
    } else {
      ans = A[1];
    }
  }
  cout << ans << endl;
  return 0;
}
