#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a.at(i);
  sort(a.begin(), a.end());
  cout << min(a.at(n - 2) - a.at(0), a.at(n - 1) - a.at(1)) << endl;
}
