#include <bits/stdc++.h>
using namespace std;
int arr[200001];
int main() {
  int N;
  int temp;
  int i;
  int m = 0;
  long long sum = 0;
  for (i = 0; i < N; i++) {
    cin >> temp;
    arr[i] = temp;
    m = max(m, arr[i]);
    sum += m - arr[i];
  }
  cout << sum;
}
