#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  priority_queue<int> q;
  scanf("%d", &n);
  int buff;
  for (int i = 0; i < n; i++) {
    scanf("%d", &buff);
    q.push(buff);
  }
  int ans = 0;
  int max = q.top();
  q.pop();
  while (!q.empty()) {
    ans += max - q.top();
    q.pop();
  }
  printf("%d\n", ans);
  return 0;
}
