#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, j, n, mx, mn, a;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%I64d", &a);
    if (i == 0) {
      mx = a;
      mn = a;
    }
    if (mx < a) mx = a;
    if (mn > a) mn = a;
  }
  mx = mx - mn;
  mx = mx + 1 - n;
  cout << mx << endl;
  return 0;
}
