#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; i++) {
    cin >> s;
    v.push_back(s);
  }
  sort(v.begin(), v.end());
  int mini = v[0];
  int maxi = v[v.size() - 1];
  if (maxi - v[1] <= v[v.size() - 2] - mini) {
    cout << maxi - v[1];
  } else
    cout << v[v.size() - 2] - mini;
}
