A generalization of Taketa's theorem on M-groups