#include <bits/stdc++.h>
using namespace std;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
const int drx[] = {2, 2, 1, 1, -1, -1, -2, -2};
const int dry[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int N = 400500;
long long n, a[N];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  int mx = a[n];
  int r = a[n - 1];
  int l = a[2];
  if (mx - l < r - a[1])
    cout << mx - l;
  else
    cout << r - a[1];
  return 0;
}
