#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b[100], c, xd = 0, lol;
  cin >> a;
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  for (int i = 0; i < a; i++) {
    if (i == a - 1) {
      c = b[i];
    }
  }
  for (int i = 0; i < a; i++) {
    if (b[i] <= c) {
      xd = xd + (c - b[i]);
    }
  }
  cout << xd;
}
