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