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 dimensions of the intersections of these sets with any half-line coincide, that is, \dim_{H}(\mathcal{L}\cap (-\infty, t)) = \dim_{H}(\mathcal{M}\cap (-\infty, t))\equalscolon 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}(\frac{\log |\log \varepsilon|}{|\log \varepsilon|^{2}}) , 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}(\frac{\log |\log \varepsilon|}{|\log \varepsilon|^{2}}) , then its second derivative F''(t) changes sign infinitely many times as t approaches 0 .