#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, mx = 0, mn = 100000, ans;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (i = 1; i < n; i++) {
    mx += a[i] - a[i - 1] - 1;
  }
  cout << mx;
  return 0;
}
