#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  sort(a.begin(), a.end());
  int h = 0;
  for (int i = 0; i < n; i++) {
    if (a[i + 1] > a[i]) {
      h += abs(a[i + 1] - a[i]);
    }
  }
  cout << h << endl;
  return 0;
}
