#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  int a[n + 5];
  for (int i = int(1); i <= int(n); i++) cin >> a[i];
  sort(a + 1, a + n + 1);
  cout << min(a[n] - a[2], a[n - 1] - a[1]) << '\n';
  return 0;
}
