Added N Mod M solution