#include <bits/stdc++.h>
using namespace std;
long long a[1111];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, ans = 0;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  sort(a + 1, a + 1 + n);
  for (long long i = 1; i < n; i++) {
    ans = ans + (a[i + 1] - a[i] - 1);
  }
  cout << ans;
  return 0;
}
