#include <bits/stdc++.h>
using namespace std;
const int MAX = 110;
int a[MAX];
int main() {
  int n;
  scanf("%d", &n);
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    mx = max(mx, a[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += abs(a[i] - mx);
  }
  printf("%lld\n", ans);
  return 0;
}
