#include <bits/stdc++.h>
using namespace std;
int n;
int x;
void solve() {
  cin >> n;
  int a = INT_MAX, b = 0;
  for (int i = 0; i <= n - 1; i++) {
    cin >> x;
    a = min(a, x);
    b = max(b, x);
  }
  cout << b - a - n + 1 << '\n';
}
int main() {
  solve();
  return 0;
}
