#include <bits/stdc++.h>
using namespace std;
int min(long a, long b) {
  if (a > b) return a;
  return b;
}
void solve() {
  long long n;
  cin >> n;
  int a[n + 5];
  for (long long i = 0; i < n; i++) cin >> a[i];
  int b[n + 5];
  long long dem = 0;
  for (long long i = 0; i < n; i++) {
    b[i] = a[i];
  }
  sort(b, b + n);
  cout << min(b[n - 1] - b[1], b[n - 2] - b[0]);
}
int main(int argc, char const *argv[]) {
  solve();
  cout << endl;
  return 0;
}
