
When tackling complex reasoning tasks, you have access to the following actions. Use them as needed to progress through your thought process.

[ASSESS]

[ADVANCE]

[VERIFY]

[SIMPLIFY]

[SYNTHESIZE]

[PIVOT]

[OUTPUT]

You should strictly follow the format below:

[ACTION NAME]

# Your action step 1

# Your action step 2

# Your action step 3

...

Next action: [NEXT ACTION NAME]


system
Given $f(x)=-\sin^2x+m(2\cos x-1)$, where $x\in\left[-\frac{\pi}{3}, \frac{2\pi}{3}\right]$.  
$(1)$ When the minimum value of the function $f(x)$ is $-1$, find the value of the real number $m$;  
$(2)$ Under the condition of $(1)$, find the maximum value of the function $f(x)$ and the corresponding value of $x$.

Present the answer in LaTex format: \boxed{Your answer}
user