The fortifications of Mdina  are a series of defensive walls which surround the former capital city of Mdina, Malta. The city was founded as Maleth by the Phoenicians in around the 8th century BC, and it later became part of the Roman Empire under the name Melite. The ancient city was surrounded by walls, but very few remains of these have survived. The city walls were rebuilt a number of times, including by the Byzantine Empire in around the 8th century AD, the Arabs in around the 11th century, and the Kingdom of Sicily in the medieval period until the 15th century. Most of the extant fortifications were built by the Order of Saint John between the 16th and 18th centuries. The city has withstood a number of sieges, and it was defeated twice - first by the Aghlabids in 870 and then by Maltese rebels in 1798. Today, the city walls are still intact except for some outworks, and they are among the best preserved fortifications in Malta. Mdina has been on Malta's tentative list of UNESCO World Heritage Sites since 1998.
Question: How many times was the city defeated?
Answer: 2