I think you'll enjoy this example. :)
Remember how to calculate the mean of a list of $n$ numbers?
Of course you do, it's almost an insult to ask: you just add them all up, and divide by $n$.
But why is this the "right" thing to do?! You probably don't know. Well, here's why.
Say you have this list of numbers: $1$, $2$, $7$, $10$
Let's say we want to find the "center" of all of these numbers. How could you go about doing this?
Well, obviously, anything outside the range $1$ to $10$ isn't the "center" by any reasonable definition.
But, then, what's the center? Well, let's call $\mu$ the "center". What properties should $\mu$ satisfy?
Ideally, it should be as close to all the numbers as possible, as a whole.
Let's see what happens if we take the distance of each number with $\mu$, square it, and add it up:
$$d_2(\mu) = |\mu - 1|^2 + |\mu - 2|^2 + |\mu - 7|^2 + |\mu - 10|^2$$
Since the absolute values don't affect the squaring operation, we can remove them:
$$d_2(\mu) = (\mu - 1)^2 + (\mu - 2)^2 + (\mu - 7)^2 + (\mu - 10)^2$$
What happens if we find the $\mu$ that minimizes $d_2$? Well, we find the root of its derivative $d_2'$:
$$
\begin{align*}
d_2'(\mu)
= 0 &= 2(\mu - 1) + 2(\mu - 2) + 2(\mu - 7) + 2(\mu - 10) \\
0 &= \mu - 1 + \mu - 2 + \mu - 7 + \mu - 10 \\
4\mu &= 1 + 2 + 7 + 10 \\
\implies\ \ \ \ \ \ \mu &= (1 + 2 + 7 + 10) \div 4
\end{align*}
$$
Hey look, the mean $\mu$ is the minimizer of the total squared deviation from our list!
Now you may wonder: why did we use squared deviation? Why not just absolute deviation?
Well, let's try that instead:
$$
\begin{align*}
d_1(m) &= |m - 1| + |m - 2| + |m - 7| + |m - 10|
\end{align*}
$$
Now take the derivative (thanks to @Ian's comment below for the suggestion on the compact notation). Let $\mathrm{sgn}(x)$ be the signum function (equivalently, $\mathrm{sgn}(x) = |x| / x$):
$$
\begin{align*}
d_1'(m) &= \mathrm{sgn}(m - 1) + \mathrm{sgn}(m - 2) + \mathrm{sgn}(m - 7) + \mathrm{sgn}(m - 10) = 0
\end{align*}
$$
Remember that $\mathrm{sgn}$ can be either $-1$, $0$, or $1$.
Does does the $m$ that satisfies this sound familiar?
It should: any $m$ that satisfies this equation is is a median of this list!
(You may have been taught that the mean of $2$ and $7$ is "the median". In fact, that's arbitrary and there is no reason to choose $5$ as the median. In reality, if you had to choose a single number, it should be $\approx 4.85$ (I think that's 34/7), and I'll leave it as an exercise for you to figure out why.)
We see that the mean and median are very intimately related -- they are both measures of dispersion. And using the derivative, we can prove why their formulas are correct! (And if we didn't know how to calculate the mean, the derivative would tell us.)
Bonus points: if you replace the exponent with $0$ instead of $1$ or $2$, you will get back the mode as well!