#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int l;
  cin >> l;
  int sum = 0;
  for (int i = 0; i < (int)(N - 1); i++) {
    int A;
    cin >> A;
    if (l - A > 0)
      sum += l - A;
    else
      l = A;
  }
  cout << sum << endl;
}
