Mexico obtained independence from the Spanish Empire with the Treaty of Córdoba in 1821 after a decade of conflict between the royal army and insurgents for independence, with no foreign intervention. The conflict ruined the silver-mining districts of Zacatecas and Guanajuato, so that Mexico began as a sovereign nation with its future financial stability from its main export destroyed. Mexico briefly experimented with monarchy but became a republic in 1824. This government was characterized by instability, leaving it ill-prepared for a major international conflict when war broke out with the U.S. in 1846. Mexico had successfully resisted Spanish attempts to reconquer its former colony in the 1820s and resisted the French in the so-called Pastry War of 1838, but the secessionists' success in Texas and the Yucatan against the centralist government of Mexico showed the weakness of the Mexican government, which changed hands multiple times. The Mexican military and the Catholic Church in Mexico, both privileged institutions with conservative political views, were stronger politically than the Mexican state.