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