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