Just  check for carbon mobs, or even better change the parameter for M to mob/living/carbon and then do

if(!istype(M)) return