#include <bits/stdc++.h>
using namespace std;
long long fun(long long a[], long long n, long long x) {
  for (long long i = 0; i < n; i++) {
    if (a[i] + i == x) return 1;
  }
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n == 1 or n == 2) {
    cout << 0 << endl;
    return;
  }
  sort(a, a + n);
  cout << min(a[n - 2] - a[0], a[n - 1] - a[1]) << endl;
  return;
}
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
