Make sure you have backed up your device using iCloud or iTunes on your PC or Mac. Otherwise, you may lose your data.
You can connect your device using a Lightning or USB-C cable to your PC or Mac.
On your device, go to Settings - [your name] Find My - Find My iPhone/iPad, then turn off the Find My iPhone/iPad.
In iTunes or Finder (Mac), hold down the Shift key (or the Options key on a Mac) and click on Restore iPhone... button.
After iTunes has installed the .ipsw file on your device, follow the on-screen instructions to restore your data.