function Main(arg) {
  let N = arg.trim().split('\n')[0];
  let A = arg.trim().split('\n')[1].split(' ');

  let result = culc(A, 0n);
  console.log(Number(result));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function culc(array, stepCount){
  let result = getMax(array);
  stepCount += getSteps(array, result.max, result.position);

  if(result.position > 1n){
    return culc(array.slice(0, result.position), stepCount);
  } else {
    return stepCount;
  }
}

function getMax(array){
  let max = 0n;
  let position = 0;
  for (i =0; i<array.length;i++){
    if(max < BigInt(array[i])){
      max = BigInt(array[i]);
      position = i;
    };
  }
  return {'max':max, 'position':position};
}

function getSteps(array, max, position){
  let count = 0n;
  for (i = position; i<array.length;i++){
    count += max - BigInt(array[i]);
  }
  return count;
}