[proofplan]
After reordering the simple roots of $M$, the two Cartan matrices may be assumed equal. For each Lie algebra, choose Chevalley generators attached to the simple roots; these generators satisfy exactly the Chevalley-Serre relations determined by the common Cartan matrix. The Chevalley-Serre presentation theorem then identifies both $L$ and $M$ with the same Lie algebra presented by those generators and relations. Composing the two identifications gives the desired Lie algebra isomorphism.
[/proofplan]
[step:Reorder the simple roots so the Cartan matrices agree exactly]
Let $\pi$ be a permutation of $\{1,\dots,\ell\}$ such that $b_{ij} = a_{\pi(i)\pi(j)}$ for all $i,j$. Replace the ordered basis $(\beta_1,\dots,\beta_\ell)$ by $(\beta_{\pi^{-1}(1)},\dots,\beta_{\pi^{-1}(\ell)})$. Under this simultaneous reindexing of the simple roots and coroots of $M$, the Cartan matrix of $M$ becomes $A_L$. Thus it is enough to prove the result under the assumption
\begin{align*}
A_L = A_M = A = (a_{ij})_{1 \leq i,j \leq \ell}.
\end{align*}
[/step]
[step:Choose Chevalley generators for $L$ and $M$]
For each $1 \leq i \leq \ell$, let $L_{\alpha_i} \subset L$ and $L_{-\alpha_i} \subset L$ denote the root spaces for $\alpha_i$ and $-\alpha_i$. By the standard root-space structure theorem for finite-dimensional semisimple Lie algebras over an algebraically closed field of characteristic $0$, the simple root spaces $L_{\alpha_i}$ and $L_{-\alpha_i}$ are one-dimensional, and there are nonzero elements
\begin{align*}
e_i \in L_{\alpha_i}, \qquad f_i \in L_{-\alpha_i}
\end{align*}
which may be scaled so that
\begin{align*}
h_i := [e_i,f_i] \in H_L
\end{align*}
is the coroot attached to $\alpha_i$, equivalently $\alpha_j(h_i)=a_{ij}$ for every $j$.
Similarly, for each $1 \leq i \leq \ell$, let $M_{\beta_i} \subset M$ and $M_{-\beta_i} \subset M$ denote the root spaces for $\beta_i$ and $-\beta_i$. The same root-space structure theorem gives nonzero elements
\begin{align*}
E_i \in M_{\beta_i}, \qquad F_i \in M_{-\beta_i}
\end{align*}
which may be scaled so that
\begin{align*}
H_i := [E_i,F_i] \in H_M
\end{align*}
is the coroot attached to $\beta_i$, equivalently $\beta_j(H_i)=a_{ij}$ for every $j$.
For the generators in $L$, the standard root-space bracket relations give
\begin{align*}
[h_i,h_j] &= 0,\\
[h_i,e_j] &= a_{ij}e_j,\\
[h_i,f_j] &= -a_{ij}f_j,\\
[e_i,f_j] &= \delta_{ij}h_i.
\end{align*}
The same relations hold for the generators in $M$:
\begin{align*}
[H_i,H_j] &= 0,\\
[H_i,E_j] &= a_{ij}E_j,\\
[H_i,F_j] &= -a_{ij}F_j,\\
[E_i,F_j] &= \delta_{ij}H_i.
\end{align*}
[/step]
[step:Use the common Chevalley-Serre presentation]
Let $\mathfrak{g}(A)$ denote the Lie algebra over $k$ generated by symbols
\begin{align*}
x_i,\ y_i,\ t_i \qquad 1 \leq i \leq \ell
\end{align*}
subject to the Chevalley-Serre relations
\begin{align*}
[t_i,t_j] &= 0,\\
[t_i,x_j] &= a_{ij}x_j,\\
[t_i,y_j] &= -a_{ij}y_j,\\
[x_i,y_j] &= \delta_{ij}t_i,\\
(\operatorname{ad} x_i)^{1-a_{ij}}(x_j) &= 0 \quad \text{for } i \neq j,\\
(\operatorname{ad} y_i)^{1-a_{ij}}(y_j) &= 0 \quad \text{for } i \neq j.
\end{align*}
Here $\operatorname{ad} x_i: \mathfrak{g}(A) \to \mathfrak{g}(A)$ is the adjoint map $z \mapsto [x_i,z]$, and similarly for $\operatorname{ad} y_i$.
By the Chevalley-Serre presentation theorem for finite-dimensional semisimple Lie algebras over an algebraically closed field of characteristic $0$, used here as the central external classification input, the assignment
\begin{align*}
x_i &\mapsto e_i,\\
y_i &\mapsto f_i,\\
t_i &\mapsto h_i
\end{align*}
extends to a Lie algebra isomorphism
\begin{align*}
\Phi_L: \mathfrak{g}(A) \to L.
\end{align*}
The same theorem applied to $M$ gives a Lie algebra isomorphism
\begin{align*}
\Phi_M: \mathfrak{g}(A) \to M
\end{align*}
defined by
\begin{align*}
x_i &\mapsto E_i,\\
y_i &\mapsto F_i,\\
t_i &\mapsto H_i.
\end{align*}
[guided]
We now build an abstract Lie algebra from the common Cartan matrix alone. Let $\mathfrak{g}(A)$ denote the Lie algebra over $k$ generated by symbols
\begin{align*}
x_i,\ y_i,\ t_i \qquad 1 \leq i \leq \ell
\end{align*}
subject to the Chevalley-Serre relations
\begin{align*}
[t_i,t_j] &= 0,\\
[t_i,x_j] &= a_{ij}x_j,\\
[t_i,y_j] &= -a_{ij}y_j,\\
[x_i,y_j] &= \delta_{ij}t_i,\\
(\operatorname{ad} x_i)^{1-a_{ij}}(x_j) &= 0 \quad \text{for } i \neq j,\\
(\operatorname{ad} y_i)^{1-a_{ij}}(y_j) &= 0 \quad \text{for } i \neq j.
\end{align*}
Here $\operatorname{ad} x_i: \mathfrak{g}(A) \to \mathfrak{g}(A)$ is the adjoint map $z \mapsto [x_i,z]$, and $\operatorname{ad} y_i: \mathfrak{g}(A) \to \mathfrak{g}(A)$ is the adjoint map $z \mapsto [y_i,z]$.
The reason for introducing $\mathfrak{g}(A)$ is that every item in this presentation is determined by the entries $a_{ij}$ of the common Cartan matrix. No further structure from $L$ or $M$ appears in the definition. The Chevalley-Serre presentation theorem says that if a finite-dimensional semisimple Lie algebra over an algebraically closed field of characteristic $0$ is equipped with a Cartan subalgebra and an ordered basis of simple roots, then the corresponding simple positive root vectors, simple negative root vectors, and coroot elements generate the Lie algebra, and the defining relations are exactly the Chevalley-Serre relations determined by its Cartan matrix.
We verify the hypotheses for $L$. The theorem statement gives that $L$ is a finite-dimensional semisimple Lie algebra over the algebraically closed field $k$ of characteristic $0$, and the proof has chosen a Cartan subalgebra $H_L$ together with the ordered simple-root basis $(\alpha_1,\dots,\alpha_\ell)$. The generators $e_i,f_i,h_i$ were chosen from the simple root spaces and coroots, and the Cartan matrix is $A=(a_{ij})$. Therefore the Chevalley-Serre presentation theorem gives a Lie algebra isomorphism
\begin{align*}
\Phi_L: \mathfrak{g}(A) \to L
\end{align*}
determined on generators by
\begin{align*}
\Phi_L(x_i)&=e_i,\\
\Phi_L(y_i)&=f_i,\\
\Phi_L(t_i)&=h_i.
\end{align*}
We verify the same hypotheses for $M$. The algebra $M$ is also finite-dimensional and semisimple over the same algebraically closed field $k$ of characteristic $0$, and after the reindexing step its ordered simple-root basis $(\beta_1,\dots,\beta_\ell)$ has the same Cartan matrix $A=(a_{ij})$. The generators $E_i,F_i,H_i$ are the corresponding simple positive root vectors, simple negative root vectors, and coroot elements. Hence the same Chevalley-Serre presentation theorem gives a Lie algebra isomorphism
\begin{align*}
\Phi_M: \mathfrak{g}(A) \to M
\end{align*}
determined on generators by
\begin{align*}
\Phi_M(x_i)&=E_i,\\
\Phi_M(y_i)&=F_i,\\
\Phi_M(t_i)&=H_i.
\end{align*}
Thus both $L$ and $M$ are identified with the same presented Lie algebra $\mathfrak{g}(A)$, and the dependence on the common Cartan matrix is the whole content of this step.
[/guided]
[/step]
[step:Compose the two presentation isomorphisms]
Since $\Phi_L: \mathfrak{g}(A) \to L$ is an isomorphism, its inverse
\begin{align*}
\Phi_L^{-1}: L \to \mathfrak{g}(A)
\end{align*}
is a Lie algebra isomorphism. Define
\begin{align*}
\Psi: L \to M
\end{align*}
by
\begin{align*}
\Psi := \Phi_M \circ \Phi_L^{-1}.
\end{align*}
A composition of Lie algebra isomorphisms is a Lie algebra isomorphism, so $\Psi$ is an isomorphism of Lie algebras over $k$. Therefore
\begin{align*}
L \cong M.
\end{align*}
This proves the theorem.
[/step]