#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int a[1010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long s = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n - 1; ++i)
    if (a[i + 1] - a[i] != 1) s += abs(a[i + 1] - a[i] - 1);
  cout << s;
  return 0;
}
