#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n];
  long long maxx = INT_MIN;
  long long minn = INT_MAX;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    maxx = max(maxx, a[i]);
    minn = min(minn, a[i]);
  }
  long long x = maxx - minn + 1;
  cout << x - n << endl;
}
