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