Stability and species richness in complex communities