#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  while (cin >> t) {
    int ch[100000];
    for (int i = 0; i < t; i++) cin >> ch[i];
    sort(ch, ch + t);
    if (t > 1) {
      int m1 = ch[t - 1] - ch[0];
      int m2 = ch[t - 2] - ch[0];
      int m3 = ch[t - 1] - ch[1];
      if (m1 > m2) m1 = m2;
      if (m1 > m3) m1 = m3;
      cout << m1 << endl;
    } else
      cout << "0" << endl;
  }
}
