#include <bits/stdc++.h>
using namespace std;
int main() {
  int max, i, j;
  int n;
  cin >> n;
  int total;
  int data[n];
  total = 0;
  for (i = 0; i < n; i++) {
    cin >> data[i];
  }
  max = data[0];
  for (i = 0; i < n; i++) {
    if (max < data[i]) {
      max = data[i];
    }
  }
  for (i = 0; i < n; i++) {
    while (data[i] != max) {
      total += max - data[i];
      data[i] = max;
    }
  }
  cout << total;
}
