Schleswig was a part of Denmark during the Viking Age, and became a Danish duchy in the 12th century. Denmark repeatedly tried to reintegrate the Duchy of Schleswig into the Danish kingdom. Holstein, just on the other side of the Danish border from Schleswig, was in medieval times a fief of the Holy Roman Empire. From 1460 on, the two had been ruled together by a common Duke -- who was also the King of Denmark. The Treaty of Ribe, agreed to by the Danish King in order to gain control of the both states, seemed to indicate that Schleswig and Holstein were to remain united, though that interpretation was later challenged. The Holy Roman Empire was dissolved in 1806, but the German Confederation formed in 1815 also included Holstein. By the early 19th century, Holstein's population was almost entirely ethnically German, along with much of Schleswig's.