#include <bits/stdc++.h>
using namespace std;
template <typename T>
T read() {
  T p = 1, x = 0;
  char s = getchar();
  while (s == ' ' || s == '\n') s = getchar();
  if (s == '-') p = -1, s = getchar();
  while (s >= '0' && s <= '9') {
    x = x * 10 + s - '0';
    s = getchar();
  }
  return x * p;
}
template <typename A, typename B>
void Umax(A &a, const B &b) {
  if (a < b) a = b;
}
template <typename A, typename B>
void Umin(A &a, const B &b) {
  if (a > b) {
    a = b;
  }
}
long long bin_pow(long long a, long long n) {
  if (n == 0) {
    return 1;
  }
  if (n % 2 == 1) {
    long long cnt = a * bin_pow(a, n - 1);
    return cnt;
  } else {
    long long cnt = bin_pow(a, n / 2);
    return cnt * cnt;
  }
}
const int N = (int)1e6 + 10;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
int a[N];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << min(a[n - 1] - a[1], a[n - 2] - a[0]) << endl;
  return 0;
}
