II. (40 points) Given the function
$$
f(x)=3\left(\sin ^{3} x+\cos ^{3} x\right)+m(\sin x+\cos x)^{3}
$$

has a maximum value of 2 in $x \in\left[0, \frac{\pi}{2}\right]$. Find the value of the real number $m$.