José de San Martín had already made incursions into Peru starting in 1820. He had been declared Protector of Peruvian Freedom, in August 1821 after liberating parts of the country, but the important cities and provinces still remained royalist. Bolívar and San Martín held a meeting in Guayaquil on July 26 and 27, 1822, in which they discussed plans to liberate Peru and it was decided that Bolívar and Gran Colombia would take over the task of fully liberating Peru. San Martín departed from the scene. For the next two years Colombian and Peruvian patriot forces gain more territory. On February 10, 1824, Bolívar was given immense political powers when a Peruvian congress named him dictator of Peru, which made Bolívar the head of state of a second country and allowed Bolívar to completely reorganize the political and military administration of Peru. Bolívar, assisted by Sucre, decisively defeated the remnants of the royalist cavalry on August 6, 1824, at the Battle of Junín. Sucre then destroyed the still numerically superior remnants of the royalist army at Battle of Ayacucho on December 9. South American independence was now all but secured. The only royalist area in the continent was highland country of Upper Peru, El Callao and Chiloé.