#include <bits/stdc++.h>
#include <fstream>
using namespace std;
int main()
{
int N,i,j,flag;
cin>>N; // No. of elements in the array
int A[N+1];
flag=1; // Flag initialization
for(i=0;i<N;i++) // Input
cin>>A[i];
sort(A,A+N); // Sorting the Array
for(i=N-2;i>=0;i--)
{
if(A[i]!=A[i+1])
{
cout<<A[i]<<endl; // Answer
flag=0; // We have encountered the second maximum unique element.
break;
}
}
if(flag) // Flag will be 1 if all the elemts which is the special case here.
cout<<0<<endl;
return 0;
}