#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, min, max, o1, o2, nes1, nes2;
  cin >> n;
  int a[100000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  max = a[0];
  min = a[0];
  o1 = 0;
  o2 = 0;
  for (int i = 1; i < n; i++) {
    if (max < a[i]) {
      max = a[i];
      o1 = i;
    }
    if (min > a[i]) {
      min = a[i];
      o2 = i;
    }
  }
  if (o1 != 0) {
    max = a[0];
  } else {
    max = a[1];
  }
  if (o2 != 0) {
    min = a[0];
  } else {
    min = a[1];
  }
  for (int i = 0; i < n; i++) {
    if (o1 != i & a[i] > max) {
      max = a[i];
    }
    if (o2 != i & a[i] < min) {
      min = a[i];
    }
  }
  nes1 = max - a[o2];
  nes2 = a[o1] - min;
  if (nes1 > nes2) {
    cout << nes2;
  } else {
    cout << nes1;
  }
  return 0;
}
