#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, i;
  cin >> n;
  vector<int> a(n);
  for (i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans1 = a[n - 2] - a[0];
  ll ans2 = a[n - 1] - a[1];
  ll ans = min(ans1, ans2);
  cout << ans;
}
