#include <bits/stdc++.h>
using namespace std;
int a[100006];
int main() {
  int n;
  while (cin >> n) {
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int s = min(a[n - 1] - a[1], a[n - 2] - a[0]);
    cout << s << endl;
  }
}
