#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int array[N];
  for (int i = 0; i < N; i++) {
    cin >> array[i];
  }
  int highest = -10000000;
  int total = 0;
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if (highest < array[i]) highest = array[i];
    total += array[i];
  }
  answer = (highest * N) - total;
  cout << answer;
}
