#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 123;
const int INF = 1e9 + 123;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};
int n, a[N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  sort(a + 1, a + n + 1);
  cout << min(a[n] - a[2], a[n - 1] - a[1]);
  return 0;
}
