#include <bits/stdc++.h>
const int MAXN = 1e5 + 5;
const long long MOD = 998244353;
const int INF = 0x3f3f3f3f;
const long long LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);
const double ERR = 1e-10;
const int L = 40;
const int M = 30;
using namespace std;
long long mx = -1e18;
long long mn = 1e18;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  long long a, b[MAXN], c = 0;
  cin >> a;
  if (a == 1) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < a; i++) {
    cin >> b[i];
  }
  sort(b, b + a);
  for (int i = 0; i < a; i++) {
    c += b[a - 1] - b[i];
  }
  cout << c;
  return 0;
}
