#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[1001];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    sum += a[i] - a[i - 1] - 1;
  }
  cout << sum;
}
