#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv) {
  int n;
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  sort(arr.begin(), arr.end());
  int max = arr[n - 1], min = arr[0], sec_min = arr[1], sec_max = arr[n - 2];
  if ((max - sec_max) > (sec_min - min)) {
    cout << (sec_max - min) << endl;
  } else {
    cout << (max - sec_min) << endl;
  }
  return 0;
}
