If $x, y \in M$ are each algebraic over $K$, then of course
$K(x), K(y) \subset M \tag 1$
and
$[K(x):K] = n, [K(y):K] = m < \infty; \tag 2$
now any polynomial
$f(X, Y) \in K[X, Y] \tag 3$
may be written
$f(X, Y) = \displaystyle \sum_{i, j = 0}^{i + j \le \deg f} f_{ij}X^i Y^j, \; f_{ij} \in K, \forall i, j, \tag 4$
which may be re-arranged as follows:
$f(X, Y) = \displaystyle \sum_{i, j = 0}^{i + j \le \deg f} f_{ij}X^i Y^j = \sum_{j = 0}^{j = \deg f} \left ( \sum_{i = 0}^{i = \deg f - j} f_{ij} X^i \right ) Y^j= \sum_{j = 0}^{\deg f} P_j(X)Y^j, \tag 5$
where
$P_j(X) = \displaystyle \sum_{i = 0}^{i = \deg f - j} f_{ij} X^i \in K[X]; \tag 6$
in this way we express $f(X, Y)$ as a polynomial in $Y$ with coefficients in the ring $K[X]$; that is, as an element of $K[X][Y]$:
$f(X, Y) \in K[X][Y]; \tag 7$
in the light of these remarks, we see that
$z = f(x, y) = \displaystyle \sum_{j = 0}^{\deg f} P_j(x)y^j \in K(x)(y) = K(x, y), \tag 8$
where
$P_j(x) = \displaystyle \sum_{i = 0}^{i = \deg f - j} f_{ij} x^i \in K(x). \tag 9$
By virtue of (8), we see that $z$ is algebraic over $K$ provided that
$[K(x)(y):K] = [K(x, y):K] < \infty; \tag{10}$
since
$[K(x):K] = n < \infty, \tag{11}$
we see that (10) will bind if
$[K(x)(y):K(x)] = [K(x, y):K(x)] < \infty, \tag{12}$
by virtue of
$[K(x)(y):K] = [K(x)(y):K(x)][K(x):K]; \tag{13}$
now by (2), we know that $y$ satisfies some polynomial
$\theta(X) \in K[X]; \; \theta(y) = 0, \tag{14}$
with
$\deg \theta \le m; \tag{15}$
but since
$\theta(X) \in K[X] \subset K(x)[X], \tag{16}$
it follows that
$[K(x)(y):K(x)] \le m; \tag{17}$
therefore (13) yields
$[K(x)(y):K] = [K(x)(y):K(x)][K(x):K] \le mn; \tag{18}$
now (8) and (18) act together in collusion to prove that $z$ is algebraic over $K$.