#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, x;
int mini = inf, secmin = inf, maxi = 0, secmax = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    if (x >= maxi) {
      secmax = maxi;
      maxi = x;
    } else if (x > secmax)
      secmax = x;
    if (x <= mini) {
      secmin = mini;
      mini = x;
    } else if (x < secmin)
      secmin = x;
  }
  printf("%d\n", min(maxi - secmin, secmax - mini));
  return 0;
}
