#include <bits/stdc++.h>
using namespace std;
const int N = 100;
int n;
int main() {
  scanf("%d", &n);
  vector<int> arr;
  int x;
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    arr.push_back(x);
  }
  sort(arr.begin(), arr.end());
  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    if (arr[i + 1] - arr[i] > 1) {
      ans += arr[i + 1] - arr[i] - 1;
    }
  }
  cout << ans << endl;
  return 0;
}
