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