#include <bits/stdc++.h>
using namespace std;
const long long int cons = 55;
const long long int MOD = 1000000007;
const long long int const_INT_MAX = 100000000000000000;
const long long int const_INT_MIN = -1 * 100000000000000000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  long long int sum1 = a[n - 1] - a[1];
  long long int sum2 = a[n - 2] - a[0];
  cout << min(sum1, sum2) << "\n";
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
