The evolution of low-mass close binary systems. I. The evolutionary fate of contact binaries