Can be calculated efficiently with the Extended Euclidean algorithm.

math.stackexchange.com/questions/2382011/computational-complexity-of-modular-exponentiation-from-rosens-discrete-mathem mentions:
can be calculated in:
Remember that $log(m)$ and $log(n)$ are the lengths in bits of $m$ and $n$, so in terms of the length in bits $M$ and $N$ we'd get:

$b_{n}modm$

$log(m)_{2}log(n)$

$M_{2}N$