import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class MagicIndex {
    public int getMagicIndex(int [] nums) {
        return getMagicIndex(nums, 0, nums.length - 1);
    }

    public int getMagicIndex(int [] nums, int s, int e) {
        if (s > e) {
            return -1;
        } else {
            int mid = (e + s) / 2;

            if (nums[mid] > mid) {
                return getMagicIndex(nums, s, mid - 1);
            } else if (nums[mid] < mid) {
                return getMagicIndex(nums, mid + 1, e);
            } else {
                return mid;
            }
        }
    }

    public static void main(String[] args) {
        MagicIndex magic = new MagicIndex();

        int [] nums = {-2, -1, 1, 3, 5};

        System.out.println(magic.getMagicIndex(nums));
    }
}