#include <bits/stdc++.h>
using namespace std;
int n, a[100001];
int main() {
  cin >> n;
  for (int k = 1; k <= n; k++) cin >> a[k];
  sort(a + 1, a + n + 1);
  if (n == 2) {
    cout << 0;
    return 0;
  }
  int p = min(a[n] - a[2], a[n - 1] - a[1]);
  cout << p;
  return 0;
}
