#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) { return (b == 0) ? a : GCD(b, a % b); }
long long oo = 1e18;
int const M = 1e9 + 7, N = 1e5 + 9;
int n, m, k;
map<string, int> mb;
map<string, string> ms;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<int> v(n);
  int x;
  for (int i = 0; i < n; i++) cin >> v[i];
  int c = 0;
  sort(v.begin(), v.end());
  for (int i = 0; i < n - 1; i++) {
    c += v[i + 1] - v[i] - 1;
  }
  cout << c;
  return 0;
}
