using System;
using System.Linq;

namespace atc
{
    class Program
    {
        static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            long[] p = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            int count = 0;
            for (int iii = 0; iii < num - 1; iii++)
            {
                while (true)
                {
                    if (p[iii] <= p[iii + 1])
                        break;
                    else
                    {
                        p[iii + 1] += 1;
                        count++;
                    }
                }
            }
            Console.WriteLine(count);
        }
    }
}
