Contemporary Croatia, which gained independence in 1991, is the successor of the 9th century Croatian medieval prinicipalities established in the marches of the Carolingian Empire, followed by the Kingdom of Croatia, founded in 925 by King Tomislav. Soon after the death of the last great Croatian king, Dmitar Zvonimir, Croatia entered into a personal union with Hungary, while the French Anjou dynasty acceded to the throne in the 14th century. After the Ottoman invasions in the 16th century and the loss of much territory, Croatian dignitaries elected Ferdinand Habsburg as monarch in 1527, and the country remained within the Habsburg Monarchy until 1918. The first half of this period was marked by constant wars with the Ottomans and Venetian encroachment upon territories along the coast (Istria and Dalmatia), apart from the far south, where the independent Dubrovnik Republic developed trade in the Mediterranean between 1358 and 1808. After the defeat of Venice and a short period in which southern Croatia was incorporated in Napoleon’s Illyrian Provinces (1809–13), all the Croatian lands were brought together within the Habsburg Monarchy, though they were still separate entities. After the First World War, Croatia became part of the Kingdom of Yugoslavia, which was transformed after 1945 into a Communist federation, in which Croatia was one of six republics until 1991. Although recognised as an independent state by the international community on 15 January 1992, Croatia was forced to defend its independence through armed struggle until 1995, when the occupied territories were liberated. In 1992, Croatia became a member of the United Nations, in 2009, of NATO, and on 1 July 2013, of the European Union. Croatia will preside over the Council of the EU in the first half of 2020.