#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long a[n], c = 0;
  for (long long i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  int j = a[0];
  for (long long i = 0; i < n; i++) {
    if (a[i] != j) {
      c = c + abs(a[i] - j);
      j = a[i] + 1;
    }
    j = a[i] + 1;
  }
  cout << c;
  return 0;
}
