To counter powerful neighbors such as the Kingdom of Dali (934–1253), the Song made alliances with tribal groups in southwest China which served as a protective buffer between their borders and Dali's. As long as these ethnic tribal groups paid tribute to the Song court and agreed to follow the course of its foreign policy, the Song agreed to grant military protection and allow the tribal leaders hereditary, autonomous local rule. During the 1050s, the Song put down local tribal insurrections along their borders with the Lý dynasty of Đại Việt, while their relations with Tai peoples and alliances with local clan leaders in the southern frontier led to a border war with Lý from 1075 to 1077.