#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int k = a[0];
  int count = 0;
  for (int i = 1; i < n; i++) {
    if (k != a[i] - 1) count += a[i] - k - 1;
    k = a[i];
  }
  cout << count;
}
