#include <bits/stdc++.h>
using namespace std;
int main(void) {
  vector<int> v;
  long long N, tmp_max_height, tmp_num, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> tmp_num;
    v.push_back(tmp_num);
  }
  tmp_max_height = v[0];
  for (int i = 0; i < v.size(); i++) {
    if (tmp_max_height > v[i]) {
      ans = ans + tmp_max_height - v[i];
    }
  }
  cout << ans << endl;
  return 0;
}
