Peru was heavily indebted, and political in-fighting was again on the rise. Peru embarked on a railroad-building program that helped but also bankrupted the country. In 1879, Peru entered the War of the Pacific which lasted until 1884. Bolivia invoked its alliance with Peru against Chile. The Peruvian Government tried to mediate the dispute by sending a diplomatic team to negotiate with the Chilean government, but the committee concluded that war was inevitable. Chile declared war on 5 April 1879. Almost five years of war ended with the loss of the department of Tarapacá and the provinces of Tacna and Arica,
First Upper Peru campaign authorities. The May Revolution, in Buenos Aires, was more successful, and ousted the viceroy Baltasar Hidalgo de Cisneros. The Primera Junta, which replaced him, prepared a military expedition to Upper Peru to secure the control of the area, while another expedition headed to Paraguay. Before proceeding to Upper Peru, this military campaign defeated a counter revolution in Córdoba, organized by the former viceroy Santiago de Liniers. Ortiz de Ocampo disobeyed orders to execute the prisoners, sending them to Buenos Aires instead. As a result, the Junta appointed Juan José Castelli as commander of the Army of the North instead of