#include <bits/stdc++.h>
using namespace std;
inline int Rand() { return (rand() << 16) | rand(); }
using namespace std;
const int N = 2e5 + 5, S = 2e3 + 5, MOD = 1e9 + 7, inf = 21e8;
const long long INF = 9e18;
const double eps = 1e-9;
int a[N], mx, ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], mx = max(mx, a[i]);
  for (int i = 1; i <= n; i++) ans += mx - a[i];
  cout << ans;
  return 0;
}
