import java.util.*;
public class Solution {
    public int search(int[] nums, int target) {
        int  res = -1;
        int low = 0, high = nums.length - 1;
        while(true) {
            int mid = midSearch(nums, low, high, target);
            int start = mid;
            while(true) {
                int temp = midSearch(nums, low, mid - 1, target);
                if(temp != -1) {
                    start = temp;
                    mid = temp;
                } else break;
            }
            res = start;
            break;
        }
        return res;
    }
    public int midSearch(int[] nums, int low, int high, int target) {
        while(low <= high) {
            int mid = (low + high) / 2;
            if(nums[mid] > target) {
                high = mid - 1;
            } else if(nums[mid] < target) {
                low = mid + 1;
            } else return mid;
        }
        return - 1;
    }
}