#include <bits/stdc++.h>
using namespace std;
int n, a[103], max1, result = 0;
int main() {
  cin >> n;
  max1 = a[1];
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    max1 = max(max1, a[i]);
  }
  for (int i = 1; i <= n; i++) {
    result += (max1 - a[i]);
  }
  cout << result << endl;
  return 0;
}
