#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, sum = 0;
  cin >> a;
  int b[1001];
  for (int i = 0; i < a; i++) cin >> b[i];
  for (int i = 1; i < a; ++i)
    for (int j = 0; j < a - i; j++)
      if (b[j] > b[j + 1]) {
        int d = b[j];
        b[j] = b[j + 1];
        b[j + 1] = d;
      }
  for (int i = 0; i < a - 1; i++) {
    sum += b[i + 1] - b[i] - 1;
  }
  cout << sum;
}
