#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n);
    for (auto &i : a) {
      cin >> i;
    }
    long long j;
    int sum = 0;
    long long c = 0;
    sort(a.begin(), a.end());
    for (int i = 0; i < n - 1; i++) {
      if (a[i + 1] > a[i]) {
        sum = sum + (a[i + 1] - a[i]);
      }
    }
    cout << sum;
  }
}
