#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans1, ans2;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  ans1 = a[n - 1] - a[1];
  ans2 = a[n - 2] - a[0];
  if (ans1 > ans2)
    cout << ans2;
  else
    cout << ans1;
  return 0;
}
