#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 1e5 + 1;
long long n, cnt = 0;
long long F[NMAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for (long long i = 1; i <= n; ++i) cin >> F[i];
  sort(F + 1, F + n + 1);
  if (n == 1) {
    cout << "0";
    return 0;
  }
  F[0] = F[1] - 1;
  for (long long i = 1; i <= n; ++i)
    if (F[i - 1] + 1 != F[i]) cnt += F[i] - (F[i - 1] + 1);
  cout << cnt;
}
