#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
char arr[205][205];
int arr1[205][205] = {0};
bool visited[205][205];
int prime[10005] = {0};
set<long long int> st;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    st.insert(k);
  }
  auto it = st.rbegin();
  it--;
  if (st.size() != 1)
    cout << *it << endl;
  else
    cout << 0 << endl;
}
