#include <bits/stdc++.h>
using namespace std;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int i, j, k, m, n, p, p1, q, r, cnt = 0, maxi = 0, mini = INF, a, b,
                                            c, d, ans, t;
  cin >> n;
  long long int A[n];
  for (i = 0; i < n; i++) {
    cin >> A[i];
  }
  if (n == 2) {
    cout << 0 << endl;
  } else {
    sort(A, A + n);
    ans = min(A[n - 1] - A[0], min(A[n - 1] - A[1], A[n - 2] - A[0]));
    cout << ans << endl;
  }
}
