#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, r, i = 0, m, k, j, b = 0, c;
  long long int s = 1, v = 0;
  string st;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  s = a[n - 1] - a[1];
  v = a[n - 2] - a[0];
  cout << min(s, v);
  return 0;
}
