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