#include<bits/stdc++.h>
using namespace std;
int main(){
int n; cin >> n;
vector<int> a(n);
for(int i=0;i<n;i++) cin >> a[i];
if(n == 2){
cout << "0";
return 0;
}
sort(a.begin(),a.end());
cout << min(a[n-1]-a[1],a[n-2]-a[0]);
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCl7CglpbnQgbjsJY2luID4+IG47Cgl2ZWN0b3I8aW50PiBhKG4pOwoJZm9yKGludCBpPTA7aTxuO2krKykJY2luID4+IGFbaV07CglpZihuID09IDIpewoJCWNvdXQgPDwgIjAiOwoJCXJldHVybiAwOwoJfQkKCXNvcnQoYS5iZWdpbigpLGEuZW5kKCkpOwoJY291dCA8PCBtaW4oYVtuLTFdLWFbMV0sYVtuLTJdLWFbMF0pOwoJcmV0dXJuIDA7Cn0=