The history of Latvia spans several millennia, with Finno-Ugric and Baltic peoples inhabiting the region as early as 3000 BC. From the 9th to 11th centuries, Vikings raided the Baltic lands, and in the late 12th century German merchants and Christian missionaries arrived. Riga was founded by Germans in 1201 and became an important trading post in 1282. Latvia came under Polish-Lithuanian rule in the 14th century before being conquered by Sweden. Russia gained influence over Latvia in the 18th century during the Great Northern War. Latvia declared independence in 1918 after World War I but was occupied by the Soviet Union in 1940 and Nazi Germany from 1941-1944 before being reoccupied by the Soviet Union until 1991