#include <bits/stdc++.h>
using namespace std;
int const MOD = 1e9 + 7;
double const PI = acos(-1);
long long const oo = 8e18;
int const N = 5e5 + 100;
int const M = 1e6 + 100;
int main() {
  int n, a[1100], ans = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  for (int i = 1; i < n; ++i) ans += a[i] - a[i - 1] - 1;
  cout << ans << endl;
  return 0;
}
