#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[1001];
  int b[1001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]] = 1;
  }
  sort(a, a + n);
  int ans = 0;
  int sum = a[n - 1] - a[0] + 1;
  cout << sum - n << endl;
  return 0;
}
