#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  int a[100006];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  return !printf("%d\n", min(a[n - 2] - a[0], a[n - 1] - a[1]));
}
