#include <bits/stdc++.h>
using namespace std;
int n, a[101], sum;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a, a + n);
  for (int i = n - 2; i >= 0; --i) sum += a[n - 1] - a[i];
  cout << sum;
  return 0;
}
