#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a, b, x, d;
  while (cin >> n) {
    cin >> d;
    a = d;
    b = d;
    for (int j = 1; j < n; j++) {
      int c;
      cin >> c;
      if (a <= c) a = c;
      if (b >= c) b = c;
    }
    x = a - b + 1 - n;
    cout << x << endl;
  }
  return 0;
}
