#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, d, ans = 0, ma = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> d;
    ma = max(d, ma);
    if (i != 0 || ma == d) ans += ma - d;
  }
  cout << ans << endl;
  return 0;
}
