The Duchy of Bohemia was incorporated into the Holy Roman Empire in 1004 during the German-Polish Wars, that lasted from 1002 to 1018. Emperor Henry II installed Jaromir as Duke of Bohemia and guaranteed protection against Polish aggression. Jaromir ruled only a small territory, however, as Poland had occupied the traditional Czech territories of Moravia, Silesia, Lesser Poland and Lusatia. In 1012, Jaromir was deposed by his brother Oldrich, who assumed the Bohemian throne for himself. Following the resumption of hostilities between the Empire and Poland in 1028, Oldrich went on the offensive against Poland, reconquering Moravia by 1029, which helped to stabilize his duchy. The war ended in 1031 when Polish King Mieszko II surrendered to Conrad. During the following civil war, Mieszko was forced to flee Poland for Bohemia, where Oldrich had him imprisoned and castrated in revenge for the torture Mieszko's father, Bolesław I of Poland, inflicted upon Duke Boleslaus III, Oldrich's brother, thirty years before.