#include <bits/stdc++.h>
using namespace std;
const int mm = 1e5 + 10;
long long a1, a2, a3, a4, a5, a6, a7, a8, n, m, ans;
int inp[mm];
void input() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> inp[i];
  }
  sort(inp, inp + n);
}
void solve() {
  for (int i = 0; i < n - 1; i++) {
    ans += abs(inp[i] - inp[i + 1]) - 1;
  }
  cout << ans << endl;
}
int main() {
  input();
  solve();
  return 0;
}
