Germany's second largest city and principal port started out as a castle called Hammaburg which was built by Emperor Charlemagne in 808 AD as a defence against Slavic invaders. Hamburg was officially granted the status of “Imperial Free City” by Frederick I (Barbarossa) in 1189. Its location close to the North Sea and the Baltic Sea soon made the northern outpost one of Europe's leading ports. Hamburg's rise to prominence was sealed by its trade alliance with Lübeck in 1241, which marked the origin of the Hanseatic League, a powerful union of trading guilds that maintained a stronghold on trade in most of northern Europe for over 400 years. Hamburg continues to cultivate this link to its glorious past even today, often referring to itself, like Lübeck and Bremen, as a “Free and Hansa City”. It is the second wealthiest metropolis in the EU after London and a leading media, industrial, commercial and cultural centre.