#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
  int d = 0, n;
  cin >> n;
  vector<long long> vect;
  long long mas[1000];
  for (int i = 0; i < n; i++) {
    cin >> mas[i];
    vect.push_back(mas[i]);
  }
  sort(vect.begin(), vect.end(), cmp);
  for (int i = 0; i < n - 1; i++) {
    if (vect[i] > vect[i + 1] + 1) {
      d += vect[i];
      d -= vect[i + 1];
      d--;
    }
  }
  cout << d;
  return 0;
}
