#include <bits/stdc++.h>
using namespace std;
const int N = 1000050;
bool arr[N];
int main() {
  int n, x;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  if (v.size() == 1)
    cout << 0 << '\n';
  else {
    cout << min(v[v.size() - 2] - v[0], v[v.size() - 1] - v[1]) << '\n';
  }
  return 0;
}
