#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, x;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  int a = v[n - 1] - v[0];
  int b = v[n - 2] - v[0];
  int c = v[n - 1] - v[1];
  int m = min(a, min(b, c));
  cout << m << endl;
  return 0;
}
