The territory of modern Khakassia was the core of the old Yenisei Kirghiz state from the 6th century CE. In the 13th century, following a defeat by the Mongols, the majority of the Kyrgyz people migrated southwest to Central Asia to what now is Kyrgyzstan. Modern Khakas people regard themselves as the descendants of those Kyrgyz who remained in Siberia. Khakassia was incorporated into the Russian state under Peter the Great. This incorporation was confirmed in a treaty between Russia and China in 1729. As it was common to deport convicted criminals from European Russia to Siberia, forts were quickly constructed in Khakassia (1707 and 1718). Many prisoners remained even after release. Many of the indigenous Khakas people converted to the Russian Orthodox faith and gradually abandoned their nomadic way of life.