#include <bits/stdc++.h>
using namespace std;
void test() {
  int n;
  cin >> n;
  long long a[n], sum = 0;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i < n; i++) sum += (a[i] - a[i - 1] - 1);
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) test();
  return 0;
}
