#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int ar[n];
  for (long long int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  sort(ar, ar + n);
  long long int sum = 0;
  for (long long int i = 0; i < n - 1; i++) {
    sum += ar[i + 1] - ar[i];
  }
  cout << sum << endl;
  return 0;
}
