Let $f:D \longrightarrow \mathbb{R}$ be a function where $D \subset \mathbb{R}$ which is not monotonic. Then there exists a 'cap' or a 'cup' in its graph, namely, there are $a,b,c \in D$ such that $a<b<c$ and $f(a), f(c) < f(b) \vee f(b) < f(a), f(c)$.
Ok. This is easy. Easy enough so that we have frequently seen the phrase saying that '…so, evidently, there are three numbers $a<b<c$ so that either $f(a), f(c) < f(b)$ or $f(b) < f(a), f(c)$' at the stage where the function $f$ is not monotonic. However, this is rarely had been proved. I guess it is high time to search for a 'good' and/or 'short' and/or 'easy' proofs.
Constant functions are monotonic, so suppose $f$ is not constant. Thus there are $a,b$ with $a < b$ and $f(a) \ne f(b)$. We may suppose $f(a) < f(b)$ (otherwise consider $-f$ instead of $f$). Suppose there are no "cups" or "caps". I claim $f$ is non-decreasing.
Putting these together, $f$ is nondecreasing on all of $D$.