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