By June 1813 Belgrano set up a base in Potosí with an army of 2,500 men, to prepare an attack on Upper Peru. Goyeneche moved to Oruro and resigned, being replaced by Joaquín de la Pezuela. Belgrano administrated the zone and tried to revert the bad impression left by the previous campaign of Juan José Castelli. Belgrano initiated good relations with the natives as well. Belgrano's plan was to attack the royalists from the front and the sides, with the aid of the armies of Cárdenas and Zelaya. Both armies were near 3,500 men. However, the royalists obtained an important advantage by defeating Cárdenas and getting possession of his papers, which gave them insight into the patriotic plans. Belgrano was taken by surprise at Vilcapugio on 1 October, and initially gained the upper hand against the royalist troops, who started to flee. However, when Pezuela saw that the patriotic armies were not following, he reorganised his forces, returned to the battle, and won. There were barely 400 survivors. Belgrano said: "Soldiers: we have lost the battle after so much fighting. Victory has betrayed us by going to the enemy ranks during our triumph. It does not matter! The flag of the nation still swings in our hands!". After gathering his army at Macha, where he received reinforcements from Cochabamba, Belgrano was ready for another engagement with Pezuela, whose troops were not in a better situation. On 14 November, Belgrano was again vanquished by the royalists at Ayohuma, and was forced to withdraw the remains of his army towards Potosí and from there to Jujuy.