agreement in the village of Andrusovo near Smolensk, according to which eastern Ukraine now belonged to Russia (with a high degree of local autonomy and an internal army). The truce's provisions were favorable to the Tsardom, which, through the territorial gains secured, stopped the Polish eastern expansion and facilitated its own future further movement to the west. The Smolensk, Chernihiv and Novhorod-Siverskyi regions were for Poland from now lost, in addition to left-bank Ukraine with Kiev and Zaporizhian Sich (the last entity for a short while remained under joint Russian-Polish supervision). "Polish Livonia", the Polotsk and Vitebsk voivodeships and area north of Dünaburg (Latgalia) were to be kept by the Commonwealth. Adjustments were still going to take place, but the eastern and northern Polish–Lithuanian borders had mainly stabilized, until the time of the First Partition. Period of wars with the Ottoman Empire, John III Sobieski The Ottoman Empire, which had previously been involved in Ukrainian affairs by Bohdan Khmelnytsky, now under the leadership of Sultan Mehmed IV and his Grand Vizier Ahmed Köprülü, interpreted the Ukrainian disorder as an opportunity for its own expansion in the region. The Commonwealth's friend, Tatar Khan Mehmed IV Giray was removed in 1666 and Petro Doroshenko, the Cossack hetman of right-bank Ukraine, seeking the threatened by the Polish-Russian negotiations unity of Ukraine, accepted Ottoman suzerainty. In fall of 1666, the Tatars eliminated the Commonwealth military units present in Dnieper Ukraine, but the 1667 sejm reduced the country's army to 20,000 nevertheless. In 1667, when Tatar-Cossack forces attacked Lwów (Lviv), Hetman John Sobieski confronted them with a small force. After the Polish troops withstood two weeks of enemy assaults at the Battle of Podhajce (Pidhaitsi), the Tatars agreed to renew the alliance with the Commonwealth and Doroshenko acknowledged its authority. Soon King John II Casimir Vasa abdicated and was replaced by the helpless Michał Korybut Wiśniowiecki, which coincided with intense factional infighting within the Commonwealth. Doroshenko's proposal of granting the Cossacks full autonomy in return for Ukraine's association with the Commonwealth was rejected, and a Polish committee nominated Mykhailo Khanenko for Doroshenko's hetman post. Doroshenko appealed for help to the Turks and their Tatar allies, but the Tatars were defeated twice by Sobieski, who in 1671 removed them and Doroshenko from the Bratslav Voivodeship. At that point, however, the Ottomans, having successfully concluded their war with Venice over Crete, were ready to wage a war