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