using System;

namespace Constest
{
    class Program
    {
        static void Main(string[] args)
        {
            string cnt = Console.ReadLine();
            string line = Console.ReadLine();
            string[] stArrayData = line.Split(' ');
            int max = 0;
            int sum = 0;
            foreach (string s in stArrayData)
            {
                int i = int.Parse(s);
                if(max < i)
                {
                    max = i;
                }
                sum += (max - i);
            }
            Console.WriteLine(sum);
        }
    }
}
