#include <bits/stdc++.h>
using namespace std;
int n;
int data[100001];
void solve() {
  memset(data, 0, sizeof(data));
  scanf("%d", &n);
  int a;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a);
    data[i] = a;
  }
  if (n == 2) {
    printf("0");
    return;
  }
  sort(data, data + n);
  int v1 = 0;
  if (data[0] == data[1])
    v1 = data[n - 1] - data[0];
  else
    v1 = data[n - 1] - data[1];
  int v2 = 0;
  if (data[n - 1] == data[n - 2])
    v2 = data[n - 1] - data[0];
  else
    v2 = data[n - 2] - data[0];
  printf("%d", min(v1, v2));
}
int main(int size, char** args) { solve(); }
