  The Lagrange spectrum $\mathcal{L}$ and Markov spectrum $\mathcal{M}$ are
subsets of the real line with complicated fractal properties that appear
naturally in the study of Diophantine approximations. It is known that the
Hausdorff dimension of the intersection of these sets with any half-line
coincide, that is, $\mathrm{dim}_{\mathrm{H}}(\mathcal{L} \cap (-\infty, t)) =
\mathrm{dim}_{\mathrm{H}}(\mathcal{M} \cap (-\infty, t)):= d(t)$ for every $t
\geq 0$. It is also known that $d(3)=0$ and $d(3+\varepsilon)>0$ for every
$\varepsilon>0$.
  We show that, for sufficiently small values of $\varepsilon > 0$, one has the
approximation $d(3+\varepsilon) = 2\cdot\frac{W(e^{c_0}|\log
\varepsilon|)}{|\log \varepsilon|}+\mathrm{O}\left(\frac{\log |\log
\varepsilon|}{|\log \varepsilon|^2}\right)$, where $W$ denotes the Lambert
function (the inverse of $f(x)=xe^x$) and $c_0=-\log\log((3+\sqrt{5})/2)
\approx 0.0383$. We also show that this result is optimal for the approximation
of $d(3+\varepsilon)$ by "reasonable" functions, in the sense that, if $F(t)$
is a $C^2$ function such that $d(3+\varepsilon) = F(\varepsilon) +
\mathrm{o}\left(\frac{\log |\log \varepsilon|}{|\log \varepsilon|^2}\right)$,
then its second derivative $F''(t)$ changes sign infinitely many times as $t$
approaches $0$.
