#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x) {
  char ch = getchar();
  x = 0;
  t f = 1;
  while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : f), ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
long long a[100050], ans = 0;
int main() {
  int n;
  read(n);
  for (int i = 0; i < n; ++i) read(a[i]);
  sort(a, a + n);
  for (int i = 1; i < n; ++i) ans += a[i] - a[i - 1] - 1;
  printf("%lld ", ans), puts(" ");
  return 0;
}
