#include <bits/stdc++.h>
int main() {
  int n;
  std::vector<int> a;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    std::cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int instability = a[a.size() - 1] - a[0];
  if (a[a.size() - 1] - a[a.size() - 2] > a[1] - a[0]) {
    std::cout << instability - (a[a.size() - 1] - a[a.size() - 2]) << std::endl;
  } else {
    std::cout << instability - (a[1] - a[0]) << std::endl;
  }
  return 0;
}
