#include <bits/stdc++.h>
using namespace std;
vector<int> InputNumbes(int NumbersCount) {
  vector<int> Result(NumbersCount);
  for (int i = 0; i < NumbersCount; i++) {
    cin >> Result[i];
  }
  return Result;
}
void PrintResult(vector<int> Result) {
  for (int i = 0; i < Result.size(); i++) {
    cout << Result[i] << " ";
  }
}
int main() {
  int n;
  cin >> n;
  vector<int> arr = InputNumbes(n);
  sort(arr.begin(), arr.end());
  long long int cnt = 0;
  for (int i = 1; i < arr.size(); i++) {
    cnt += (arr[i] - arr[i - 1] - 1);
  }
  cout << cnt;
}
