solve NmodM challenge