#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  int mx, mn, a, i;
  scanf("%d", &n);
  mx = -1e9;
  mn = 1e9 + 1;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a);
    mx = max(mx, a);
    mn = min(mn, a);
  }
  printf("%d\n", (mx - mn + 1) - n);
  return 0;
}
