#include <bits/stdc++.h>
using namespace std;
int maxa = -1, mina = 1000000000;
int main() {
  int n, o;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> o;
    maxa = max(maxa, o);
    mina = min(mina, o);
  }
  cout << ((maxa - mina) - 1) - (n - 2);
}
