toward Livonia, the Swedes blocked their further progress by taking over Dünaburg (Daugavpils). King Charles X Gustav of Sweden was also encouraged by the Polish magnate opposition unhappy with John Casimir's rule; Hieronim Radziejowski, expelled form the Commonwealth by the sejm court, was the magnates' representative in Stockholm. The Commonwealth nobility hoped that acquiring the Swedish monarch's protection, or even accepting his rule, would help them recover the eastern lands lost in the warfare of the past several years. The Swedish armies entered the Commonwealth from the Pomeranian and Livonian dominions, the Pomeranian force crossing the border under Arvid Wittenberg on July 25. At the Battle of Ujście, Greater Poland's pospolite ruszenie briefly fought, but soon capitulated and sought Charles Gustav's protection for their province. Magnus De la Gardie's army crossed into Lithuania with promises of help in resisting the Russians. Janusz and Bogusław Radziwiłł there accepted the Swedish king's supremacy and on October 20 signed the Union of Kėdainiai treaty, under which Lithuania was to form a union with Sweden, instead of Poland. Other provinces of the Polish Crown by that time had also surrendered to the King of Sweden. Warsaw did not resist the invaders and was thoroughly plundered. John Casimir fought, but was defeated at the Battle of Żarnów and sought refuge, first in Żywiec district and then in Oberglogau in the Duchy of Oppeln (Opole) in Silesia, outside of the Crown. Kraków was defended with determination for three weeks under Stefan Czarniecki's command, but had to capitulate when a rescue force was crushed by the Swedes in the Battle of Wojnicz. The bulk of the Polish nobility and the armed forces declared loyalty to Charles Gustav. The Swedes failed to take advantage of the local support and treated the Commonwealth as a conquered country, subjecting it to widespread violence, predatory contributions, ruthlessness and pillage. Spontaneous popular resistance arose first among the peasants, beginning with a skirmish they fought near Myślenice. Partisan groups included also townspeople and szlachta, who disillusioned with Charles Gustav often switched sides and took the lead of the fighting. Krzysztof Żegocki led the uprising in Greater Poland. Carpathian foothills region units were highly successful, liberating Nowy Sącz and many other towns. Lwów (Lviv) and Zamość resisted both the Cossack and the Swedish assaults, similarly Danzig (Gdańsk) and Marienburg in case of the Swedes. Some of the Lithuanian forces, under Paweł Jan Sapieha, had