The unified kingdom of Denmark emerged in the eighth century as a proficient maritime power amid the struggle for control of the Baltic Sea. In 1397, it joined Norway and Sweden to form the Kalmar Union, until the latter's secession in 1523; the remaining Kingdom of Denmark–Norway persisted until 1814. Beginning in the 17th century, several wars with the Swedish Empire resulted in territorial cessions, and following the Napoleonic Wars, Norway was absorbed into Sweden while Denmark kept the Faroe Islands, Greenland, and Iceland. A surge of nationalist movements in the 19th century were defeated in the First Schleswig War, though the Second Schleswig War of 1864 resulted in the loss of the Duchy of Schleswig to Prussia. Denmark remained neutral during World War I but regained the northern half of Schleswig in 1920. In April 1940, a German invasion saw brief military skirmishes while the Danish resistance movement was active from 1943 until the German surrender in May 1945. An industrialised exporter of agricultural produce in the second half of the 19th century, Denmark introduced social and labour-market reforms in the early 20th century that created the basis for the present welfare state model with a highly developed mixed economy.