*What I had written first required differentiability I apologize. This is the same idea although quite unelegant in this form. Thanks Vim for pointing out my error.
First understand why the definition of a convex function means that its graph between any two points $[c,d]$ is below the line through those two points.
Observe that $f$ cannot decrease after it has been increasing. If $f$ is convex in an interval [c,d] if $max \{ f(x) \ | \ x\in [c,d]\}=f(x_m)$ for $c<x_m<d$ let $c<x_l<x_m<x_r<d$. Then the line through $x_l$ and $x_r$ lies below $f(x)$.
This means that if $f(x)$ is an increasing function in any interval $[a,u]$ it is an increasing function in the whole domain $[a,b]$.
CASE 1: If $f(x)$ is an increasing function $m(x)=f(x)$.
CASE 2: If $f(x)$ is a decreasing function in an interval $[a,u]$ we have two subcases.
2.1 If$f(a)=max\{ f(x) \ | \ x\in[a,b]\}$, then $m(x)=f(a)=const$. Hence it is convex.
2.2 There is a point $x_a\in [a,b)$ such that f(x_a)=f(a).
In that case $$m(x)=\cases{f(a)=const \ \ \ x\in [a,x_a] \\ f(x) \ \ \ \ \ x\in (x_a, b]}$$
Now we must prove that $m(x)\leq m(c)+ (m(d)-m(c))\frac{x-c}{d-c}$, for $x\in [a,b]$ for all $c,d\in [a,b]$.
We already have the cases where $c,d \in [a,x_a]$ or $a,b \in[x_a,b]$.
So we have to prove it for $c\in [a,x_a)$ and $d\in(x_a,b]$ which is readily obvious.
$$\forall x\in[a,x_a] \ \ m(x)=m(a)\leq m(c)+ (m(d)-m(c))\frac{x-c}{d-c}$$
$$\forall x\in(x_a,b] \ \ m(x) = f(x) \leq m(c)+ (m(d)-m(c))\frac{x-x_a}{d-x_a}\leq m(c)+ (m(d)-m(c))\frac{x-c}{d-c}$$.
Since in that interval $$\frac{x-x_a}{d-x_a}\leq \frac{x-c}{d-c}$$