The first Finno-Ugric tribes appeared here in the 3rd century BC. The territories remained independent up until the 13th century. From 1220 through 1918 Estonia was under a foreign rule. The southern part was occupied by the Livonian Order, and the northern part – by Denmark. After the breakup of the Livonian Order, the northern part was conquered by the Swedish people and the southern part – by the Polish-Lithuanian Commonwealth. In 1645 Sweden acquired control over all the territories of Estonia. Following the end of the Great Northern War (1700 – 1721), Russia annexed the territories of Estonia and Latvia. Estonia declared its independence in 1918, but later was occupied by Germany and fought against the Soviet Union in 1918 - 1920. The first constitution established the parliamentary system of government. In 1934 K. Päts, Head of the Government, made a coup d’état and established a conservative dictatorship. The second constitution restored the parliamentarianism. In 1940 Estonia was occupied and annexed by the Soviet Union. The Popular Front of Estonia and some other organizations demanded the separation from the Soviet Union. The Declaration of Sovereignty was adopted in 1988. In 1991 Estonia declared its independence. Later that year Estonia became a member of the United Nations and joined the European Union in 2004.