#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  vector<int> vc;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tk;
    cin >> tk;
    vc.push_back(tk);
  }
  sort(vc.begin(), vc.end());
  cout << min(vc[vc.size() - 2] - vc[0], vc[vc.size() - 1] - vc[1]);
}
