#include <bits/stdc++.h>
using namespace std;
long long ara[10003];
int main() {
  long long n;
  scanf("%lld", &n);
  long long mx = 0;
  long long mn = 999999999999999;
  for (long long i = 1; i <= n; i++) {
    scanf("%lld", &ara[i]);
    mx = max(mx, ara[i]);
    mn = min(mn, ara[i]);
  }
  long long cnt = mx - mn + 1 - n;
  ;
  cout << cnt << endl;
}
