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