#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int main()
{
int n;
cin>>n;
int *a=new int [n+1];
int *mins=new int [n+1];
int *maxs=new int [n+1];
memset(mins,0,sizeof mins);
memset(maxs,0,sizeof maxs);
bool flag=true;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=j)
{
if (a[i]<a[j])
{
maxs[i]++;
}
else if (a[i]>a[j])
{
mins[i]++;
}
}
}
if (mins[i]==maxs[i])
{
cout<<a[i]<<endl;
flag=false;
break;
}
flag=true;
}
if(flag)
cout<<-1<<endl;
}