#include <bits/stdc++.h>
using namespace std;
int* input() {
  int cout;
  static int arr[100];
  return arr;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, maxx = 0, cnt = 0;
  int a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    maxx = max(a[i], maxx);
  }
  if (n <= 1) {
    cout << cnt << endl;
  } else {
    for (int i = 0; i < n; i++) {
      int temp = abs(maxx - a[i]);
      cnt += temp;
    }
    cout << cnt << endl;
  }
  return 0;
}
