#include <bits/stdc++.h>
int main(void) {
  int i, n, b[1001], high, low;
  scanf("%d", &n);
  int pos[n];
  for (i = 0; i < n; i++) scanf("%d", &pos[i]);
  for (i = 0; i <= 1000; i++) b[i] = 0;
  for (i = 0; i < n; i++) b[pos[i]] = 1;
  for (i = 1; i <= 1000; i++)
    if (b[i] == 1) {
      low = i;
      break;
    }
  for (i = 1000; i > 0; i--)
    if (b[i] == 1) {
      high = i;
      break;
    }
  printf("%d\n", high - low);
  return 0;
}
