#include <bits/stdc++.h>
int comp(const void *p, const void *q) {
  int l = *(const int *)p;
  int r = *(const int *)q;
  if (l > r)
    return 1;
  else if (l == r)
    return 0;
  else
    return -1;
}
int main() {
  int n, a[1000000];
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  qsort((void *)a, n, sizeof(a[0]), comp);
  int ans;
  if (a[n - 1] - a[1] > a[n - 2] - a[0])
    ans = a[n - 2] - a[0];
  else
    ans = a[n - 1] - a[1];
  if (n == 2) ans = 0;
  printf("%d\n", ans);
  return 0;
}
