Ulm is mentioned as a demesne in 854, and under the Carolingian dynasty it was the scene of several assemblies. It became a town in 1027, and was soon the principal place in the Duchy of Swabia. Although burned down by Henry the Lion, the town soon recovered, becoming a Free Imperial City in 1155. Towards the close of the Middle Ages it played a leading part several times at the head of Swabian Leagues of the 14th century and 15th century. Its trade and commerce prospered, peaking in the 15th century, ruling over a district about 300 square miles. It became a Free Imperial City with extensive territorial authority, and having a population of about 60,000. It became Protestant in 1530 and declined after the French Wars of Religion of the 16th century and 17th century. In 1802 it lost its Imperial immediacy and passed to Electorate of Bavaria, being ceded to Kingdom of Württemberg in 1810. In October 1805 General Karl Mack von Leiberich and his 23,000 Austrian troops capitulated to Napoleon here. Ulm is remarkable in the history of German literature as the spot where the Meistersingers lingered longest, orally preserving the traditional folklore of their craft.