#include <bits/stdc++.h>
using namespace std;
int f[10001];
int main() {
  int a, b = -99999, c = 0;
  cin >> a;
  for (int i = 1; i <= a; i++) cin >> f[i];
  for (int i = 1; i <= a; i++) b = max(b, f[i]);
  for (int i = 1; i <= a; i++) c += (b - f[i]);
  cout << c << endl;
  return 0;
}
