#include <bits/stdc++.h>
using namespace std;
vector<int> V;
int main() {
  long long n = 0, iNumber = 0, iSum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> iNumber;
    V.push_back(iNumber);
  }
  sort(V.begin(), V.end());
  for (int i = 0; i < n - 1; i++) {
    if (V[i + 1] - V[i] > 1) {
      iSum += (V[i + 1] - V[i] - 1);
    }
  }
  cout << iSum << "\n";
  return 0;
}
