The first traces of settlement in the area of modern Chełm date back to at the least 9th century. The following century, a fortified town ("gord") was created and initially served as a centre of pagan worship. The etymology of the name is unclear, though most scholars derive it from the Proto-Slavic noun denoting a flat hill. The town's centre is located on a hill called "góra chełmska". However, it is also theorized that the name is derived from some Celtic root. In 981 the town, then inhabited by the Slavic tribe of Buzhans, was annexed from Poland by the Kyivan Rus', along with the surrounding Cherven Towns. According to a local legend, Vladimir the Great built the first stone castle there in 1001. Following the Polish capture of Kyiv in 1018, the region returned to Poland before it fell back to Kyivan rule in 1031.