#include <bits/stdc++.h>
template <class F, class S>
std::istream& operator>>(std::istream& is, std::pair<F, S>& pair) {
  return is >> pair.first >> pair.second;
}
template <class T>
std::vector<T> load_array(std::size_t len, std::istream& is = std::cin) {
  std::vector<T> vec;
  vec.resize(len);
  for (std::size_t i = 0; i < len; i++) {
    is >> vec[i];
  }
  return vec;
}
template <class T>
std::vector<T> load_vector(std::istream& is = std::cin) {
  std::size_t size;
  is >> size;
  if (!is) return {};
  return load_array<T>(size, is);
}
template <class T>
std::ostream& print(const std::vector<T>& container, const char delim = ' ',
                    std::ostream& os = std::cout) {
  bool first = true;
  for (const auto& elem : container) {
    if (first) {
      first = false;
    } else {
      os.put(delim);
    }
    os << elem;
  }
  return os;
}
template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& container) {
  return print(container, ' ', os);
}
template <class T>
using Iter = typename std::vector<T>::iterator;
int main() {
  while (1) {
    auto citizens = load_vector<int>();
    if (!std::cin) break;
    auto m = *std::max_element(citizens.begin(), citizens.end());
    auto s = std::accumulate(citizens.begin(), citizens.end(), 0);
    std::cout << citizens.size() * m - s << "\n";
  }
  return 0;
}
