C++| Brute-force | O(n*m)
\nclass Solution {\npublic:\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        set<int> st;\n        map<int,int> mp
```\nclass Solution {\npublic:\n    int earliestSecondToMarkIndices(vector<int>& nums, vector<int>& changeIndices) {\n        set<int> st;\n        map<int,int> mp;\n        int n=nums.size(),m=changeIndices.size();\n        for(int i=0;i<m;i++){\n            st.insert(changeIndices[i]);\n            mp[changeIndices[i]]=i;\n            if(st.size()==n){\n                set<int> yolo;\n                for(auto p:mp) yolo.insert(p.second);\n                int cnt=0;\n                bool f=true;\n                for(int j=0;j<=i;j++){\n                    if(yolo.count(j)){\n                        if(cnt>=nums[changeIndices[j]-1]){\n                            cnt=cnt-nums[changeIndices[j]-1];\n                        }\n                        else f=false;\n                    }\n                    else cnt++;\n                }\n                if(f) return i+1;\n            }\n        }\n        return -1;\n    }\n};\n```
['Greedy']