#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  int num[n];
  int may = 0, rta = 0;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
    if (num[i] > may) may = num[i];
    rta += may - num[i];
  }
  cout << rta << "\n";
  return 0;
}
