Swedish forces entered Poland-Lithuania from Swedish Pomerania in the west, and Livonia in the north. The division on the western flank consisted of 13,650 men and 72 artillery pieces commanded by Arvid Wittenberg who entered Poland on 21 July 1655 and another 12,700 to 15,000 commanded by Charles X Gustav who followed in August, while the division on the northern flank consisted of 7,200 men commanded by Magnus De la Gardie who had already seized Dünaburg with them on 12 July. On the western front, Wittenberg was opposed by a Polish levy of 13,000 and an additional 1,400 peasant infantry. Aware of the military superiority of the well-trained Swedish army, the nobles of Greater Poland surrendered to Wittenberg on 25 July in Ujście after the Battle of Ujście, and then pledged loyalty to the Swedish king. Wittenberg established a garrison in Poznań . On the northern front, Prince Janusz Radziwiłł signed the Treaty of Kėdainiai with Sweden on 17 August 1655, placing the Grand Duchy of Lithuania under Swedish protection. Though Radziwiłł had been negotiating with Sweden before, during his dispute with the Polish king, Kėdainiai provided a clause stipulating that the two parts of the Commonwealth, Poland and Lithuania, need not fight each other. Part of the Lithuanian army opposed the treaty however, forming a confederation led by the magnate and Polish-Lithuanian hetman Paweł Jan Sapieha at Wierzbołów.
Question: Which happened first, the Battle of Ujście or the signing of the Treaty of Kėdainiai?
Answer: the Battle of Ujście