First Order Conditions for Ideal Minimization of Matrix-Valued Problems