#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, b, c = 0, d;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  b = a[0];
  d = a[n - 1];
  c = d - b + 1;
  cout << c - n << endl;
}
