#include <bits/stdc++.h>
using namespace std;
long long n, a[1000], ans;
string s;
map<long long, long long> mp;
pair<int, string> p;
vector<long long> v;
bool b;
char c;
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n - 1; i++) ans += a[n - 1] - a[i];
  cout << ans << endl;
  ;
  return 0;
}
