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