#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m, x = 0, j = 1;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 2) {
    cout << 0;
    return 0;
  }
  sort(a.begin(), a.end());
  cout << min(a[n - 2] - a[0], a[n - 1] - a[1]);
}
