Murat established a plan of conquest, sending two large armies to attack pockets of pro-Ferdinand resistance. One army secured the route between Madrid and Vitoria and besieged Zaragoza, Girona, and Valencia. The other, sent south to Andalusia, sacked Córdoba. Instead of proceeding to Cádiz as planned, General Dupont was ordered to march back to Madrid, but was defeated by General Castaños at Bailén on 22 July 1808. This victory encouraged the resistance against the French in several countries elsewhere in Europe. After the battle, King Joseph left Madrid to take refuge in Vitoria. In the fall of 1808, Napoleon himself entered Spain, entering Madrid on 2 December and returning Joseph I to the capital. Meanwhile, a British army entered Spain from Portugal but was forced to retreat to Galicia. In early 1810, the Napoleonic offensive reached the vicinity of Lisbon, but were unable to penetrate the fortified Lines of Torres Vedras.