#include <bits/stdc++.h>
using namespace std;
long long a[1000005];
int main() {
  int n;
  cin >> n;
  multiset<long long> s;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s.insert(a[i]);
  }
  long long ans = 1e9;
  for (int i = 1; i <= n; i++) {
    s.erase(s.find(a[i]));
    long long mi = *s.begin();
    auto it = s.end();
    it--;
    long long ma = *it;
    ans = min(ans, ma - mi);
    s.insert(a[i]);
  }
  cout << ans;
  return 0;
}
