#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  for (auto &value : arr) cin >> value;
  sort(arr.rbegin(), arr.rend());
  cout << min(arr[1] - arr[n - 1], arr[0] - arr[n - 2]) << endl;
  return 0;
}
