Python (Simple Binary Search)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution:\n    def earliestSecondToMarkIndices(self, nums, changeIndices):\n        n, m = len(nums), len(changeIndices)\n\n        def dfs(x):\n            visited, ops = set(), 0 \n\n            for i in range(x-1,-1,-1):\n                if changeIndices[i] not in visited:\n                    ops += nums[changeIndices[i]-1]\n                    visited.add(changeIndices[i])\n                elif ops:\n                    ops -= 1\n\n            return ops == 0 and len(visited) == n \n            \n\n        low, high = 0, m \n\n        while low <= high:\n            mid = (low+high)//2  \n            if dfs(mid):\n                high = mid - 1\n            else:\n                low = mid + 1 \n\n        return low if low != m+1 else -1 \n            \n        \n```
['Python3']