#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a = 1e9;
  int b = -1e9;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    a = min(a, t);
    b = max(b, t);
  }
  cout << b - a + 1 - n << endl;
  return 0;
}
