See, when $m$ is a point of maxima then $f(m)$ is negative and there is a point $f(a)=0$, then this is a contradiction that maximum value is less than some other value. And the same argument is applicable when $m$ is a point of minima.
And is maxima or minima attends at end points, then maxima = minima