#include <bits/stdc++.h>
using namespace std;
int main() {
  int v[200000];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> v[i];
  sort(v, v + n);
  if (v[n - 1] - v[1] < v[n - 2] - v[0])
    cout << v[n - 1] - v[1] << endl;
  else
    cout << v[n - 2] - v[0] << endl;
}
