#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int arr[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
  }
  sort(arr, arr + n);
  int temp = arr[n - 2] - arr[0];
  int temp1 = arr[n - 1] - arr[1];
  printf("%d\n", min(temp, temp1));
  return 0;
}
