#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-6;
const long long mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
const int maxm = 100 + 10;
long long a[maxn];
int main() {
  long long n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  sort(a + 1, a + 1 + n);
  long long ans = 0;
  for (int i = 2; i <= n; i++) {
    if (a[i] != a[i - 1] + 1) {
      ans = ans + a[i] - a[i - 1] - 1;
    }
  }
  cout << ans << endl;
}
