of Warmia and the town of Braniewo (Braunsberg) co-founded the Prussian Confederation, which opposed Teutonic rule, and most towns of the Warmia joined the organization in May 1440. In February 1454, the organization asked Polish King Casimir IV Jagiellon to incorporate the region to the Kingdom of Poland, to which the king agreed and signed the act of incorporation in Kraków on 6 March 1454, and the Thirteen Years' War (1454–1466) broke out. During the war Warmia was recaptured by the Teutonic Knights, however, in 1464 Bishop Paweł Legendorf vel Mgowski sided with Poland and the Prince-Bishopric came again under the overlordship of the Polish King. In the Second Peace of Thorn (1466) the Teutonic Knights renounced any claims to Warmia, and recognized Polish sovereignty over the region, which was confirmed to be part of Poland. It was administratively remained a Prince-Bishopric with several privileges, part of the larger provinces of Royal Prussia and Greater Poland Province. Soon after, in 1467, the Cathedral Chapter elected Nicolas von Tüngen against the wish of the Polish king. The Estates of Royal Prussia did not take the side of the Cathedral Chapter. Nicholas von Tüngen allied himself with the Teutonic Order and with King Matthias Corvinus of Hungary. The feud, known as the War of the Priests, was a low scale affair, affecting mainly Warmia. In 1478 Braniewo (Braunsberg) withstood a Polish siege which was ended in an agreement in which the Polish king recognized von Tüngen as bishop and the right of the Cathedral Chapter to elect future bishops, which however would have to be accepted by the king, and the bishop as well as Cathedral Chapter swore an oath to the Polish king. Later in the Treaty of Piotrków Trybunalski (7 December 1512), conceded to the king of Poland a limited right to determine the election of bishops by choosing four candidates from Royal Prussia. The region retained autonomy, governing itself and maintaining its own laws, customs, rights and German language. Warmia was invaded by the Teutonic Knights during the Polish–Teutonic War of 1519–1521, however, the Poles, led by renown astronomer Nicolaus Copernicus, repulsed the Teutonic siege of Olsztyn in 1521. Copernicus spent more than half of his life in Warmia, where he wrote many of his groundbreaking works and conducted astronomical observations and mathematical calculations, which became the basis for his heliocentric model of the universe. After the war of