Generalization of Anderson's theorem for disordered superconductors