In 1821, Mexico won its independence from Spain, and San Diego became part of the Mexican territory of Alta California. In 1822, Mexico began attempting to extend its authority over the coastal territory of Alta California. The fort on Presidio Hill was gradually abandoned, while the town of San Diego grew up on the level land below Presidio Hill. The Mission was secularized by the Mexican government in 1833, and most of the Mission lands were sold to wealthy Californio settlers. The 432 residents of the town petitioned the governor to form a pueblo, and Juan María Osuna was elected the first alcalde ("municipal magistrate"), defeating Pío Pico in the vote. (See, List of pre-statehood mayors of San Diego.) However, San Diego had been losing population throughout the 1830s and in 1838 the town lost its pueblo status because its size dropped to an estimated 100 to 150 residents. Beyond town Mexican land grants expanded the number of California ranchos that modestly added to the local economy.