#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 5;
const long long N = 205;
void solve();
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(10);
  long long _ = 1;
  while (_--) solve();
  return 0;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  sort(v.rbegin(), v.rend());
  long long cnt = 0;
  for (long long i = 0; i < n - 1; i++) {
    long long x = v[i] - v[i + 1] - 1;
    if (x) cnt += x;
  }
  cout << cnt << "\n";
}
