#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const int mx = 5000000;
const long long infL = 0xf3f3f3f3f3f3f3f;
const double eps = 1e-9;
const double pi = acos(-1.0);
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i <= (int)n - 1; i++) scanf("%d", &a[i]);
  sort(a, a + n);
  int x = abs(a[n - 2] - a[0]);
  int y = abs(a[n - 1] - a[1]);
  printf("%d", (int)min(x, y)), printf("\n");
  return 0;
}
