#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const int N = 1e5 + 7;
int arr[N];
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  cout << min(arr[n - 2] - arr[0], arr[n - 1] - arr[1]);
  return 0;
}
