/*
Task: Problem 6.07
Date: Dec 24, 2020
Author: aLittleLove (Minh Vu)
*/

#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("input.txt","r",stdin);
    int n; cin >> n;
    set<int> s;
    for (int i=1; i<=n; i++)
    {
        int x; cin >> x;
        s.insert(x);
    }
    if (s.size()<2) cout << 0; // it hon 2 phan tu -> ko co phan thu lon thu 2
    else 
    {
        set<int>::reverse_iterator it = s.rbegin(); //phan tu o cuoi s (phan tu lon nhat)
        it++; //di nguoc lai den phan tu lon thu 2
        cout << *it;
    }
    return 0;
}