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