#include <bits/stdc++.h>
using namespace std;
long long solve() {
  long long c;
  cin >> c;
  vector<long long> v(c);
  for (long long i = 0; i < c; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  long long sum = 0;
  for (long long i = 1; i < c; i++) {
    sum += v[i] - v[i - 1] - 1;
  }
  cout << sum;
  return 0;
}
int32_t main() {
  long long t = 1;
  while (t--) solve();
}
