#include <bits/stdc++.h>
using namespace std;
void mergee(int a[], int i1, int j1, int i2, int j2, int n) {
  int temp[n];
  int i, j, k;
  i = i1;
  j = i2;
  k = 0;
  while (i <= j1 && j <= j2) {
    if (a[i] < a[j])
      temp[k++] = a[i++];
    else
      temp[k++] = a[j++];
  }
  while (i <= j1) temp[k++] = a[i++];
  while (j <= j2) temp[k++] = a[j++];
  for (i = i1, j = 0; i <= j2; i++, j++) a[i] = temp[j];
}
void mergesort(int a[], int i, int j, int n) {
  int mid;
  if (i < j) {
    mid = (i + j) / 2;
    mergesort(a, i, mid, n);
    mergesort(a, mid + 1, j, n);
    mergee(a, i, mid, mid + 1, j, n);
  }
}
int main() {
  int n;
  cin >> n;
  int a[n];
  int i, j;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  mergesort(a, 0, n - 1, n);
  int c = 0;
  for (i = 0; i < n - 1; i++) {
    while (a[i] < a[i + 1] - 1) {
      c++;
      a[i]++;
    }
  }
  cout << c;
}
