#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  set<int> keyboards;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    keyboards.insert(a);
  }
  int prev = 0;
  int result = 0;
  for (auto keyboard : keyboards) {
    if (prev != 0) result += (keyboard - prev - 1);
    prev = keyboard;
  }
  printf("%d\n", result);
}
