#include <bits/stdc++.h>
using namespace std;
int a[101];
int main() {
  int n, x;
  cin >> n;
  while (n--) {
    cin >> x;
    a[x]++;
  }
  int cnt = 0, i, j;
  int two = 0;
  for (i = 1; i < 101;) {
    if (a[i] > 0) {
      a[i]--;
      for (j = i; j < 101; j++) {
        if (a[j] > 0) {
          a[j]--;
          cnt += abs(i - j);
          break;
        }
      }
      i = j;
    } else
      i++;
  }
  cout << cnt << endl;
}
