After the Treaty of Königsberg in 1656 during the Northern Wars, Elector Frederick William opened Memel's harbor to Sweden, with whom the harbor's revenue was divided. Prussian independence from Poland and Sweden was affirmed in the Treaty of Oliva in 1660. The construction of a defence system around the entire town, initiated in 1627, noticeably changed its status and prospects. In November 1678 a small Swedish army invaded Prussian territory, but was unable to capture the fortress of Memel. By the beginning of the 18th century, Memel was one of the strongest fortresses ("Memelfestung") in Prussia, and the town became part of the Kingdom of Prussia in 1701. Despite its fortifications, it was captured by Russian troops during the Seven Years' War in 1757. Consequently, from 1757–1762 the town, along with the rest of eastern Prussia, was dependent on the Russian Empire. After this war ended, the maintenance of the fortress was neglected, but the town's growth continued. Memel became part of the province of East Prussia within the Kingdom of Prussia in 1773. In the second half of the 18th century Memel's lax customs and Riga's high duties enticed English traders, who established the first industrial sawmills in the town. In 1784, 996 ships arrived in Memel, 500 of which were English. (In 1900 there was still an active English church in Memel, as well as a "British Hotel"). The specialisation in wood manufacturing guaranteed Memel's merchants income and stability for more than a hundred years. During this era it also normalised its trade relations with Königsberg; regional instability had degraded relations since the 16th century. Memel prospered during the second half of the 18th century by exporting timber to Great Britain for use by the Royal Navy. In 1792, 756 British ships visited the town to transport lumber from the Lithuanian forests near Memel. In 1800 its imports consisted chiefly of salt, iron and herrings; the exports, which greatly exceeded the imports, were corn, hemp, flax, and, particularly, timber. The 1815 "Encyclopædia Britannica" stated that Memel was "provided with the finest harbour in the Baltic". During the Napoleonic Wars, Memel became the temporary capital of the Kingdom of Prussia. Between 1807 and 1808, the town was the residence of King Frederick William III, his consort Louise, his court, and the government.