#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int min(int a, int b) {
  if (a < b) return a;
  return b;
}
void solve() {
  int n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  sort(v.begin(), v.end());
  if (n == 2) {
    cout << 0 << '\n';
    return;
  }
  cout << min(min(v[n - 1] - v[1], v[n - 2] - v[0]), v[n - 1] - v[0]);
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int T = 1;
  while (T--) {
    solve();
  }
}
