//https://www.geeksforgeeks.org/find-a-fixed-point-in-a-given-array/
#include<iostream>
using namespace std;
int binary(int a[],int l,int r){
if (l<=r){
int m=(l+r)/2;
if (a[m]==m)
return m;
else if (a[m] > m)
return binary(a,0,m-1);
return binary(a,m+1,r);
}
return -1;
}
int main(){
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int j=binary(a,0,n-1);
cout<<j;
}