Groups with finitely many derived subgroups