#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
long long n, a[N];
int z, zz, zzz;
vector<int> v;
string s;
void ans() {
  z = v[n - 1] - v[0];
  zz = v[n - 2] - v[0];
  zzz = v[n - 1] - v[1];
  cout << min(z, min(zz, zzz)) << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  ans();
  return 0;
}
