IF $P$ divides $b,$ the remainder will be $0$
Else $(b,P)=1$
$$((b^{M_1})^{M_2})^{M_3}\cdots)^{M_n}=b^{M_1\cdot M_2\cdot M_3\cdots M_n}$$
As $P$ is prime, $a^{P-1}\equiv\pmod P$ if $(a,P)=1$ using Fermat's Little Theorem.
So, we need to find $M_1\cdot M_2\cdot M_3\cdots M_n\pmod {(P-1)}$
Then use repeated exponentiation.