Mexico gained independence from Spain on August 24, 1821, upon conclusion of the decade-long Mexican War of Independence. As the successor state to the Viceroyalty of New Spain, Mexico automatically included the provinces of Alta California and Baja California as territories. Alta California declared allegiance to the new Mexican nation and elected a representative to be sent to Mexico. On November 9, 1822, the first legislature of California was created. With the establishment of a republican government in 1824, Alta California, like many northern territories, was not recognized as one of the constituent States of Mexico because of its small population. The 1824 Constitution of Mexico refers to Alta California as a "territory".