The ispán or count was the leader of a castle district in the Kingdom of Hungary from the early 11th century. Most of them were also heads of the basic administrative units of the kingdom, called counties, and from the 13th century the latter function became dominant. The ispáns were appointed and dismissed by either the monarchs or a high-ranking royal official responsible for the administration of a larger territorial unit within the kingdom. They fulfilled administrative, judicial and military functions in one or more counties.