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