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