How can I find the answer of this type of modular exponentiation? Here, one thing should be noticed, that is 'MOD' value may or may not be prime. I need a generalized formula/method. Similar type question was asked before but there was solution under various condition. I didn't find my answer.
$$ (a^{b^{c^{{d^\ddots}^z}}})\bmod M\ =\ ?\ [\ 1\leq (a,b,c,....z,M) \leq 10^{16}\ ]$$