The immediate task of the new dynasty was to restore order. However, Russia's major enemies, Poland and Sweden, were engaged in a conflict with each other, which provided Russia the opportunity to make peace with Sweden in 1617. The Polish–Muscovite War (1605–1618) was ended with the Truce of Deulino in 1618, restoring temporarily Polish and Lithuanian rule over some territories, including Smolensk, lost by the Grand Duchy of Lithuania in 1509.