afterwards he fought in the battles of junin and ayacucho