land was granted to the monastery, it was exempt from all feudal lords except the king and later the Holy Roman Emperor (a condition known as Imperial immediacy; in German or ). The privileged position of the abbey (reduced taxes and greater autonomy) encouraged the other men of the valley to put themselves under the authority of abbey. By doing so they gained the advantages of the Imperial immediacy and grew used to the relative freedom and autonomy. The only source of royal or imperial authority was the or of the abbey which was given to one family after another by the emperor as a sign of trust. In the 10th century, the rule of the Carolingians waned: Magyars destroyed Basel in 917 and St. Gallen in 926, and Saracenes ravaged the Valais after 920 and sacked the monastery of St. Maurice in 939. The Conradines (von Wetterau) started a long time rule over Swabia during this time. Only after the victory of king Otto I over the Magyars in 955 in the Battle of Lechfeld were the Swiss territories reintegrated into the empire. High Middle Ages King Rudolph III of the Arelat kingdom (r. 993–1032) gave the Valais as his fiefdom to the Bishop of Sion in 999, and when Burgundy and thus also the Valais became part of the Holy Roman Empire in 1032, the bishop was also appointed count of the Valais. The Arelat mostly existed on paper throughout the 11th to 14th centuries, its remnants passing to France in 1378, but without its Swiss portions, Bern and Aargau having come under Zähringer and Habsburg rule already by the 12th century, and the County of Savoy was detached from the Arelat just before its dissolution, in 1361. The dukes of Zähringen founded many cities, the most important being Freiburg in 1120, Fribourg in 1157, and Bern in 1191. The Zähringer dynasty ended with the death of Berchtold V in 1218, and their cities subsequently thus became independent, while the dukes of Kyburg competed with the house of Habsburg over control of the rural regions of the former Zähringer territory. When the house of Zähringen died out in 1218 the office of Vogt over the Abbey of St Felix and Regula in Zurich was granted to the Habsburgs, however it was quickly revoked. The rise of the Habsburg dynasty gained momentum when their main local competitor, the Kyburg