#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;
  int tmp;
  vector<int> A;
  vector<int> B;
  for (int i = 0; i < N; i++) {
    cin >> tmp;
    A.emplace_back(tmp);
  }
  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;
}
