#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
  int n;
  scanf("%d", &n);
  int minn = inf, maxx = 0;
  for (int i = 1; i <= n; i++) {
    int t;
    scanf("%d", &t);
    if (t < minn) minn = t;
    if (t > maxx) maxx = t;
  }
  int ans = maxx - minn + 1 - n;
  printf("%d\n", ans);
  return 0;
}
