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