#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ma = 0, mi = 1000000001;
  cin >> n;
  long long m[n];
  for (int i = 0; i < n; i++) {
    cin >> m[i];
    ma = max(ma, m[i]);
    mi = min(mi, m[i]);
  }
  long long p = abs(n - 2 - (ma - mi - 1));
  cout << p;
}
