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