/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
			int arr[]={-1,0,3,5,9,12};
			int target=2;
			int res = searchInsert(arr,target);	
			System.out.println(res);
	}
	
	public static int searchInsert(int[] nums, int target) {
        int left=0,right=nums.length-1,ans=nums.length;
        while(left <= right){
            int mid = left+(right - left) / 2;
            if(nums[mid] == target ){
                return mid;
            }else if(nums[mid] > target){
                ans = mid;
                right = mid - 1;
            }else{
                left = mid+1;
            }
        }
        return ans;
    }
}