Easiest java Solution
Code\n\nclass Solution {\n    public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n        int a=earliestsec(nums,changeIndices);\n       
# Code\n```\nclass Solution {\n    public int earliestSecondToMarkIndices(int[] nums, int[] changeIndices) {\n        int a=earliestsec(nums,changeIndices);\n        if(a==-1)return -1;\n        return a+1;\n    }\n    private static int earliestsec(int[]nums,int[]changeidx){\n        int ans=-1;\n        int l=0;\n        int u=changeidx.length-1;\n        while(l<=u){\n            int m=l+(u-l)/2;\n            if(possible(m,nums,changeidx)){\n                ans=m;\n                u=m-1;\n            }\n            else{\n                l=m+1;\n            }\n        }\n        return ans;\n    }\n    private static boolean possible(int m, int[] nums, int[] changeidx) {\n        int op=0;\n        int mark=0;\n        Integer[]last=new Integer[nums.length];\n        for(int id=0;id<=m;id++){\n            last[changeidx[id]-1]=id;\n        }\n        for(int i=0;i<=m;i++){\n            int id=changeidx[i]-1;\n            if(last[id]!=null&&last[id]==i){\n                if(op>=nums[id]){\n                    mark++;\n                    op-=nums[id];\n                }\n                else{\n                    return false;\n                }\n            }\n            else{\n                op++;\n            }\n        }\n        return mark==nums.length;\n    }\n}\n```
['Java']