The maximum number of electrons that can occupy a shell is given by the formula $2n^2$, where $n$ is the principal quantum number representing the shell number.
K shell: n = 1, maximum electrons = $2(1)^2 = 2$
L shell: n = 2, maximum electrons = $2(2)^2 = 8$
M shell: n = 3, maximum electrons = $2(3)^2 = 18$
N shell: n = 4, maximum electrons = $2(4)^2 = 32$
Therefore, the maximum number of electrons in the M shell is 18.