#include <bits/stdc++.h>
int caseno = 0;
const int MOD = 1000000007;
const long long INF = 1e18;
const long long inf = 0xFFFFFFFFFFFFFFFL;
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, x, y, a, b;
  cin >> n;
  long long ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  sort(ar, ar + n);
  cout << min(ar[n - 2] - ar[0], ar[n - 1] - ar[1]) << endl;
  return 0;
}
