#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<long long> a;
  long long second = 0, b, n;
  scanf("%I64d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%I64d", &b);
    a.push_back(b);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] - a[i] > 1) second += a[i + 1] - a[i] - 1;
  }
  printf("%I64d ", second);
  return 0;
}
