var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function (line) {
    const arr = line.split(' ').map(x => Number(x));
    let sum = 0;
    currentBig = arr[0]; 
    for (let i = 0; i < arr.length; i++) {
        currentBig = Math.max(currentBig, arr[i]);
        sum += currentBig - arr[i];
    }
    console.log(sum);
});