#include <bits/stdc++.h>
using namespace std;
struct Node {
  int x;
  Node* prev;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int j = 0, d, k = 1, y = 0, q, i, r, g, z, l, b = 0, c = 0, n, x;
  string s1, s2, s;
  cin >> n;
  Node* w;
  map<long long int, long long int> m;
  long long int a[n];
  vector<Node*> v;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  i = 0;
  cout << (a[n - 1] - a[0]) + 1 - n;
  return 0;
}
