#include<iostream>
#include<stdio.h>
using namespace std;
#include<algorithm>
#include<set>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)

const int mod=1000000007;


int main
int N;
  cin>>N;
  vector<int>a(N);
  rep(i,N)cin>>a[i];
  rep(i,N){
    int max=-100;
    int sum=0;
    max=max(max,A[i]);
    if(max!=A[i])sum=sum+(max-A[i]);
  }
  cout<<sum<<endl;
  return 0;
}