In 1821, Mexico won its independence from Spain, and San Diego became part of the Mexican territory of Alta California. In 1822, Mexico began its attempt 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 1834, and most of the Mission lands were granted to former soldiers. 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. Beyond the town, Mexican land grants expanded the number of California ranchos that modestly added to the local economy. (See, "List of pre-statehood mayors of San Diego".) However, San Diego had been losing population throughout the 1830s, due to increasing tension between the settlers and the indigenous Kumeyaay and in 1838 the town lost its pueblo status because its size dropped to an estimated 100 to 150 residents. The ranchos in the San Diego region would face Kumeyaay raids in the late 1830s and the town itself would face raids in the 1840s.